diff --git "a/data.jsonl" "b/data.jsonl" --- "a/data.jsonl" +++ "b/data.jsonl" @@ -1,250 +1,250 @@ -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.payments ( payment_id text PRIMARY KEY, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "Which staff members are managing properties, and what are the names and email addresses of those properties?"}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, p.property_name, p.email_address FROM hospitality_technology.staff s INNER JOIN hospitality_technology.properties p ON s.staff_id = p.manager_staff_id;"}, {"role": "user", "content": "Only include properties located in the United States and list the staff position as well."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name, p.email_address FROM hospitality_technology.staff s INNER JOIN hospitality_technology.properties p ON s.staff_id = p.manager_staff_id WHERE p.country_code = 'US';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n \"CREATE TABLE token_basic_info (\",\n \"coin_id character varying(100) NOT NULL, -- the id of the token\",\n \"token_name character varying(100) NOT NULL, -- the token's name\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"chain text, -- the chain that the token resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days\",\n \"highest_price_24h double precision, -- the highest price of the token in 24 hours\",\n \"lowest_price_24h double precision, -- the lowest price of the token in 24 hours\",\n \"market_cap double precision, -- the market cap of the token\",\n \"market_cap_rank bigint, -- the rank of the token market cap in desc\",\n \"market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours\",\n \"total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX)\", \n \"narrative text, -- the category or narrative of the token\",\n \"trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (coin_id, chain));\",\n\n", "conversations": [{"role": "user", "content": "Which is the token with the largest difference between its highest and lowest price in the last 24h on each chain, and what is the token's symbol and current price?"}, {"role": "assistant", "content": "SELECT chain, token_symbol, price, (highest_price_24h - lowest_price_24h) AS price_diff_24h\nFROM token_basic_info\nWHERE (chain, highest_price_24h - lowest_price_24h) IN (\n SELECT chain, MAX(highest_price_24h - lowest_price_24h) AS diff\n FROM token_basic_info\n GROUP BY chain\n)\nORDER BY price_diff_24h DESC;"}, {"role": "user", "content": "Could you also include the percentage change over 24 hours for each token in the result?"}, {"role": "assistant", "content": "SELECT chain, token_symbol, price, price_change_percentage_24h, (highest_price_24h - lowest_price_24h) AS price_diff_24h\nFROM token_basic_info\nWHERE (chain, highest_price_24h - lowest_price_24h) IN (\n SELECT chain, MAX(highest_price_24h - lowest_price_24h) AS diff\n FROM token_basic_info\n GROUP BY chain\n)\nORDER BY price_diff_24h DESC;"}, {"role": "user", "content": "I'm only interested in tokens where this price difference exceeds $5. Can you filter for that?"}, {"role": "assistant", "content": "SELECT chain, token_symbol, price, price_change_percentage_24h, (highest_price_24h - lowest_price_24h) AS price_diff_24h\nFROM token_basic_info\nWHERE (chain, highest_price_24h - lowest_price_24h) IN (\n SELECT chain, MAX(highest_price_24h - lowest_price_24h) AS diff\n FROM token_basic_info\n GROUP BY chain\n)\nAND (highest_price_24h - lowest_price_24h) > 5\nORDER BY price_diff_24h DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "List the first name and last name of employees who were hired in the year 2023, along with the name of the agency they work for."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, a.agency_name FROM government_services.employees AS e JOIN government_services.agencies AS a ON e.agency_id = a.agency_id WHERE EXTRACT(YEAR FROM e.hire_date) = 2023;"}, {"role": "user", "content": "Now, restrict the list to only include employees working for agencies with a 'Federal' jurisdiction level."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, a.agency_name FROM government_services.employees AS e JOIN government_services.agencies AS a ON e.agency_id = a.agency_id WHERE EXTRACT(YEAR FROM e.hire_date) = 2023 AND a.jurisdiction_level = 'Federal';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\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 (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment transaction\n reservation_id character varying(64), -- FK to reservations (if payment is for a stay)\n guest_id character varying(64) NOT NULL, -- FK to guests (who paid)\n bill_id character varying(64), -- FK to bills/invoices this payment applies to\n amount numeric(12,2) NOT NULL, -- amount of the payment\n currency_code character varying(3) NOT NULL, -- ISO currency code (e.g., USD, EUR)\n payment_method character varying(50) NOT NULL, -- e.g., CreditCard, Cash, BankTransfer, Points, Voucher\n card_type character varying(50), -- e.g., Visa, MasterCard, Amex (if CC)\n card_last_four character varying(4), -- last 4 digits of CC (if CC)\n transaction_ref character varying(128), -- reference ID from payment gateway or processor\n payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the payment occurred\n status character varying(50) NOT NULL, -- e.g., Pending, Succeeded, Failed, Refunded, Disputed\n staff_id_processed character varying(64), -- FK to staff (who processed the payment)\n notes text, -- notes about the payment\n PRIMARY KEY (payment_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id)\n)\n", "conversations": [{"role": "user", "content": "Show me the average base rate for each room type across all properties. Include the room type name and the calculated average rate."}, {"role": "assistant", "content": "SELECT type_name, AVG(base_rate) FROM hospitality_technology.room_types GROUP BY type_name;"}, {"role": "user", "content": "Actually, I need to see this breakdown per property as well."}, {"role": "assistant", "content": "SELECT p.property_name, rt.type_name, AVG(rt.base_rate) FROM hospitality_technology.room_types rt JOIN hospitality_technology.properties p ON rt.property_id = p.property_id GROUP BY p.property_name, rt.type_name;"}, {"role": "user", "content": "Can you filter the results to only show room types with an average base rate greater than 200?"}, {"role": "assistant", "content": "SELECT p.property_name, rt.type_name, AVG(rt.base_rate) FROM hospitality_technology.room_types rt JOIN hospitality_technology.properties p ON rt.property_id = p.property_id GROUP BY p.property_name, rt.type_name HAVING AVG(rt.base_rate) > 200;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text PRIMARY KEY, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes int, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.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.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 )\nCREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n", "conversations": [{"role": "user", "content": "List scheduled appointments, including the patient's full name, the doctor's full name, and the appointment time."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.first_name, d.last_name, a.appointment_time FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.doctors AS d ON a.doctor_id = d.doctor_id WHERE a.status = 'scheduled'"}, {"role": "user", "content": "Now, refine the results to only include appointments where the doctor's specialty is 'Cardiology'."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.first_name, d.last_name, a.appointment_time FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.doctors AS d ON a.doctor_id = d.doctor_id WHERE a.status = 'scheduled' AND d.specialty = 'Cardiology'"}, {"role": "user", "content": "Further filter these cardiology appointments to those occurring after '2024-07-01'."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.first_name, d.last_name, a.appointment_time FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.doctors AS d ON a.doctor_id = d.doctor_id WHERE a.status = 'scheduled' AND d.specialty = 'Cardiology' AND a.appointment_time > '2024-07-01'"}, {"role": "user", "content": "Also, include the appointment duration and order the results by appointment time ascending."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.first_name, d.last_name, a.appointment_time, a.duration_minutes FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.doctors AS d ON a.doctor_id = d.doctor_id WHERE a.status = 'scheduled' AND d.specialty = 'Cardiology' AND a.appointment_time > '2024-07-01' ORDER BY a.appointment_time ASC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\n", "conversations": [{"role": "user", "content": "List each player's most recent achievement unlock, showing the player_id, achievement_id, and unlocked_at timestamp."}, {"role": "assistant", "content": "SELECT pa.player_id, pa.achievement_id, pa.unlocked_at FROM gaming_technology.player_achievements pa INNER JOIN (SELECT player_id, MAX(unlocked_at) AS max_unlocked FROM gaming_technology.player_achievements GROUP BY player_id) sub ON pa.player_id = sub.player_id AND pa.unlocked_at = sub.max_unlocked;"}, {"role": "user", "content": "I got duplicate rows for some players who unlocked multiple achievements at the exact same time. Can you make sure to include all such achievements for the player, but if that's the case, list one row per achievement?"}, {"role": "assistant", "content": "SELECT pa.player_id, pa.achievement_id, pa.unlocked_at FROM gaming_technology.player_achievements pa INNER JOIN (SELECT player_id, MAX(unlocked_at) AS max_unlocked FROM gaming_technology.player_achievements GROUP BY player_id) sub ON pa.player_id = sub.player_id AND pa.unlocked_at = sub.max_unlocked;"}, {"role": "user", "content": "Instead, for each player, just show the total number of achievements unlocked on their most recent unlock timestamp."}, {"role": "assistant", "content": "SELECT pa.player_id, pa.unlocked_at AS most_recent_unlocked_at, COUNT(*) AS achievements_on_latest_time FROM gaming_technology.player_achievements pa INNER JOIN (SELECT player_id, MAX(unlocked_at) AS max_unlocked FROM gaming_technology.player_achievements GROUP BY player_id) sub ON pa.player_id = sub.player_id AND pa.unlocked_at = sub.max_unlocked GROUP BY pa.player_id, pa.unlocked_at;"}, {"role": "user", "content": "Now filter to only show players where achievements_on_latest_time is greater than 1."}, {"role": "assistant", "content": "SELECT pa.player_id, pa.unlocked_at AS most_recent_unlocked_at, COUNT(*) AS achievements_on_latest_time FROM gaming_technology.player_achievements pa INNER JOIN (SELECT player_id, MAX(unlocked_at) AS max_unlocked FROM gaming_technology.player_achievements GROUP BY player_id) sub ON pa.player_id = sub.player_id AND pa.unlocked_at = sub.max_unlocked GROUP BY pa.player_id, pa.unlocked_at HAVING COUNT(*) > 1;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.appointments ( appointment_id text PRIMARY KEY, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes int, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.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.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 )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text PRIMARY KEY, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "List appointment_id, appointment_time, patient\\u2019s full name, and doctor\\u2019s specialty for all appointments scheduled in the next 7 days."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time, p.first_name || ' ' || p.last_name AS patient_name, d.specialty FROM healthcare.appointments a JOIN healthcare.patients p ON a.patient_id = p.patient_id JOIN healthcare.doctors d ON a.doctor_id = d.doctor_id WHERE a.appointment_time BETWEEN now() AND now() + INTERVAL '7 days';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "Show the vehicle ID and the total number of fuel logs recorded for each vehicle."}, {"role": "assistant", "content": "SELECT vehicle_id , count(*) FROM transportation.fuel_logs GROUP BY vehicle_id"}, {"role": "user", "content": "Filter this list to only show vehicles with more than 5 fuel log entries."}, {"role": "assistant", "content": "SELECT vehicle_id , count(*) FROM transportation.fuel_logs GROUP BY vehicle_id HAVING count(*) > 5"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.appointments ( appointment_id text PRIMARY KEY, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes int, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.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.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text PRIMARY KEY, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "Show me a list of all doctors and the names of patients who have had an appointment with them, including doctor ID, doctor full name, patient full name, and appointment time."}, {"role": "assistant", "content": "SELECT d.doctor_id, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time\nFROM healthcare.doctors d\nJOIN healthcare.appointments a ON d.doctor_id = a.doctor_id\nJOIN healthcare.patients p ON a.patient_id = p.patient_id;"}, {"role": "user", "content": "Please refine this query to only include appointments where the status is 'Scheduled'."}, {"role": "assistant", "content": "SELECT d.doctor_id, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time\nFROM healthcare.doctors d\nJOIN healthcare.appointments a ON d.doctor_id = a.doctor_id\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nWHERE a.status = 'Scheduled';"}, {"role": "user", "content": "Also, sort the results by appointment_time in descending order and limit to the first 20 results."}, {"role": "assistant", "content": "SELECT d.doctor_id, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time\nFROM healthcare.doctors d\nJOIN healthcare.appointments a ON d.doctor_id = a.doctor_id\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nWHERE a.status = 'Scheduled'\nORDER BY a.appointment_time DESC\nLIMIT 20;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.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 )\n", "conversations": [{"role": "user", "content": "List for each game the server with the highest current player count and also show how many sessions that server has hosted. Include game_id, server_name, current_players, and session_count."}, {"role": "assistant", "content": "WITH session_counts AS ( SELECT s.server_id, s.game_id, s.server_name, s.current_players, COUNT(gs.session_id) AS session_count FROM gaming_technology.servers s LEFT JOIN gaming_technology.game_sessions gs ON s.server_id = gs.server_id GROUP BY s.server_id, s.game_id, s.server_name, s.current_players ), ranked AS ( SELECT sc.*, ROW_NUMBER() OVER (PARTITION BY sc.game_id ORDER BY sc.current_players DESC) AS rn FROM session_counts sc ) SELECT game_id, server_name, current_players, session_count FROM ranked WHERE rn = 1;"}, {"role": "user", "content": "Only include games where that top server has hosted at least 50 sessions."}, {"role": "assistant", "content": "WITH session_counts AS ( SELECT s.server_id, s.game_id, s.server_name, s.current_players, COUNT(gs.session_id) AS session_count FROM gaming_technology.servers s LEFT JOIN gaming_technology.game_sessions gs ON s.server_id = gs.server_id GROUP BY s.server_id, s.game_id, s.server_name, s.current_players HAVING COUNT(gs.session_id) >= 50 ), ranked AS ( SELECT sc.*, ROW_NUMBER() OVER (PARTITION BY sc.game_id ORDER BY sc.current_players DESC) AS rn FROM session_counts sc ) SELECT game_id, server_name, current_players, session_count FROM ranked WHERE rn = 1;"}, {"role": "user", "content": "Also display the region of the selected server."}, {"role": "assistant", "content": "WITH session_counts AS ( SELECT s.server_id, s.game_id, s.server_name, s.region, s.current_players, COUNT(gs.session_id) AS session_count FROM gaming_technology.servers s LEFT JOIN gaming_technology.game_sessions gs ON s.server_id = gs.server_id GROUP BY s.server_id, s.game_id, s.server_name, s.region, s.current_players HAVING COUNT(gs.session_id) >= 50 ), ranked AS ( SELECT sc.*, ROW_NUMBER() OVER (PARTITION BY sc.game_id ORDER BY sc.current_players DESC) AS rn FROM session_counts sc ) SELECT game_id, server_name, region, current_players, session_count FROM ranked WHERE rn = 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all conversation participants along with post_hashtag details where the participant's user_id matches the hashtag_id."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id;"}, {"role": "user", "content": "Only include participants who joined after '2024-01-01'."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id\nWHERE cp.joined_at > '2024-01-01';"}, {"role": "user", "content": "Also, order the results by joined_at descending."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id\nWHERE cp.joined_at > '2024-01-01'\nORDER BY cp.joined_at DESC;"}, {"role": "user", "content": "Finally, limit the output to the first 10 rows."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id\nWHERE cp.joined_at > '2024-01-01'\nORDER BY cp.joined_at DESC\nLIMIT 10;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List the usernames of users who liked the post with ID 'P123'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id WHERE T2.post_id = 'P123';"}, {"role": "user", "content": "Also, only include those users who have enabled email notifications."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id JOIN social_media.user_settings AS T3 ON T1.user_id = T3.user_id WHERE T2.post_id = 'P123' AND T3.email_notifications_enabled = TRUE;"}, {"role": "user", "content": "Further filter the list to only show users with a public profile."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id JOIN social_media.user_settings AS T3 ON T1.user_id = T3.user_id WHERE T2.post_id = 'P123' AND T3.email_notifications_enabled = TRUE AND T3.private_profile = FALSE;"}, {"role": "user", "content": "Please order the results by username alphabetically."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id JOIN social_media.user_settings AS T3 ON T1.user_id = T3.user_id WHERE T2.post_id = 'P123' AND T3.email_notifications_enabled = TRUE AND T3.private_profile = FALSE ORDER BY T1.username ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\n", "conversations": [{"role": "user", "content": "Count the number of documents for each unique document type."}, {"role": "assistant", "content": "SELECT document_type, COUNT(*) AS document_count FROM government_services.documents GROUP BY document_type ORDER BY document_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.claim_documents ( document_id text, claim_id text, document_type text, file_name text, file_path text, file_size_bytes integer, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "List all unique policies that have claim documents of type 'Claim Form'. For each, return the policy_number, start_date, end_date, and the document file_name."}, {"role": "assistant", "content": "SELECT DISTINCT p.policy_number, p.start_date, p.end_date, cd.file_name\nFROM insurance.policies p\nJOIN insurance.claim_documents cd ON p.policy_id = cd.claim_id\nWHERE cd.document_type = 'Claim Form';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.messages ( message_id 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) )\n", "conversations": [{"role": "user", "content": "How many messages include a media attachment?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.messages WHERE media_url IS NOT NULL AND TRIM(media_url) <> '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.services ( service_id 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.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "For each upcoming appointment in the next 7 days, list the appointment_id, scheduled_start_time, full name of the citizen, and the name of the service."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, \n c.first_name || ' ' || c.last_name AS full_name, \n s.service_name\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.services s ON a.service_id = s.service_id\nWHERE a.scheduled_start_time BETWEEN NOW() AND NOW() + INTERVAL '7 days';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "List all doctors who have prescribed medications with frequency 'Once daily', along with their specialties and the count of such prescriptions per doctor."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, d.specialty, COUNT(pr.prescription_id) AS prescription_count FROM healthcare.doctors d JOIN healthcare.prescriptions pr ON d.doctor_id = pr.doctor_id WHERE pr.frequency = 'Once daily' GROUP BY d.doctor_id, d.first_name, d.last_name, d.specialty;"}, {"role": "user", "content": "Now filter it to only show doctors who have made more than 5 such prescriptions."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, d.specialty, COUNT(pr.prescription_id) AS prescription_count FROM healthcare.doctors d JOIN healthcare.prescriptions pr ON d.doctor_id = pr.doctor_id WHERE pr.frequency = 'Once daily' GROUP BY d.doctor_id, d.first_name, d.last_name, d.specialty HAVING COUNT(pr.prescription_id) > 5;"}, {"role": "user", "content": "Can you also sort the results by prescription count in descending order?"}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, d.specialty, COUNT(pr.prescription_id) AS prescription_count FROM healthcare.doctors d JOIN healthcare.prescriptions pr ON d.doctor_id = pr.doctor_id WHERE pr.frequency = 'Once daily' GROUP BY d.doctor_id, d.first_name, d.last_name, d.specialty HAVING COUNT(pr.prescription_id) > 5 ORDER BY prescription_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "For each guest, list reservation_id, guest_id, check_in_date, and the next reservation_id and its check_in_date."}, {"role": "assistant", "content": "SELECT r1.reservation_id,\n r1.guest_id,\n r1.check_in_date,\n r2.reservation_id AS next_reservation_id,\n r2.check_in_date AS next_check_in_date\nFROM reservations r1\nLEFT JOIN reservations r2\n ON r1.guest_id = r2.guest_id\n AND r2.check_in_date = (\n SELECT MIN(check_in_date)\n FROM reservations\n WHERE guest_id = r1.guest_id\n AND check_in_date > r1.check_in_date\n );"}, {"role": "user", "content": "Only include guests who have at least two reservations."}, {"role": "assistant", "content": "SELECT r1.reservation_id,\n r1.guest_id,\n r1.check_in_date,\n r2.reservation_id AS next_reservation_id,\n r2.check_in_date AS next_check_in_date\nFROM reservations r1\nLEFT JOIN reservations r2\n ON r1.guest_id = r2.guest_id\n AND r2.check_in_date = (\n SELECT MIN(check_in_date)\n FROM reservations\n WHERE guest_id = r1.guest_id\n AND check_in_date > r1.check_in_date\n )\nWHERE r1.guest_id IN (\n SELECT guest_id\n FROM reservations\n GROUP BY guest_id\n HAVING COUNT(*) >= 2\n);"}, {"role": "user", "content": "Also, only show next reservations that occur within 30 days of the current reservation."}, {"role": "assistant", "content": "SELECT r1.reservation_id,\n r1.guest_id,\n r1.check_in_date,\n r2.reservation_id AS next_reservation_id,\n r2.check_in_date AS next_check_in_date\nFROM reservations r1\nLEFT JOIN reservations r2\n ON r1.guest_id = r2.guest_id\n AND r2.check_in_date = (\n SELECT MIN(check_in_date)\n FROM reservations\n WHERE guest_id = r1.guest_id\n AND check_in_date > r1.check_in_date\n )\n AND r2.check_in_date <= r1.check_in_date + INTERVAL '30 days'\nWHERE r1.guest_id IN (\n SELECT guest_id\n FROM reservations\n GROUP BY guest_id\n HAVING COUNT(*) >= 2\n);"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "What are the average and maximum fare amounts for each booking status?"}, {"role": "assistant", "content": "SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare\nFROM transportation.bookings\nGROUP BY status;"}, {"role": "user", "content": "Only include statuses where the average fare is greater than 50."}, {"role": "assistant", "content": "SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare\nFROM transportation.bookings\nGROUP BY status\nHAVING AVG(fare) > 50;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\n", "conversations": [{"role": "user", "content": "List the case name, case number, and date opened for all cases with a status of 'Pending'."}, {"role": "assistant", "content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE status = 'Pending';"}, {"role": "user", "content": "Now, only show cases from that list where the case type is 'Criminal'."}, {"role": "assistant", "content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE status = 'Pending' AND case_type = 'Criminal';"}, {"role": "user", "content": "Additionally, filter for cases opened in the year 2024 and sort the results by the date opened, with the oldest cases first."}, {"role": "assistant", "content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE status = 'Pending' AND case_type = 'Criminal' AND date_opened BETWEEN '2024-01-01' AND '2024-12-31' ORDER BY date_opened ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "What is the total USD value of tokens held by CEX addresses on the 'Ethereum' chain for the most recent snapshot time?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT max(snapshot_time) as max_time\n FROM cex_token_balance\n)\nSELECT sum(usd_value)\nFROM cex_token_balance ctb\nJOIN latest_snapshot ls ON ctb.snapshot_time = ls.max_time\nWHERE chain = 'Ethereum';"}, {"role": "user", "content": "Can you break down this total value by `exchange`, showing the top 3 exchanges by total USD value for that same latest snapshot on Ethereum?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT max(snapshot_time) as max_time\n FROM cex_token_balance\n)\nSELECT exchange, sum(usd_value) as total_usd_value\nFROM cex_token_balance ctb\nJOIN latest_snapshot ls ON ctb.snapshot_time = ls.max_time\nWHERE chain = 'Ethereum'\nGROUP BY exchange\nORDER BY total_usd_value DESC\nLIMIT 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "List the medical record ID and record date for all medical records that are linked to an appointment whose duration was longer than the average duration of all appointments."}, {"role": "assistant", "content": "SELECT T1.record_id, T1.record_date FROM healthcare.medical_records AS T1 JOIN healthcare.appointments AS T2 ON T1.appointment_id = T2.appointment_id WHERE T2.duration_minutes > (SELECT AVG(duration_minutes) FROM healthcare.appointments);"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text 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": "List the medication names which have never been prescribed to any patient."}, {"role": "assistant", "content": "SELECT m.medication_name\nFROM healthcare.medications m\nLEFT JOIN healthcare.prescriptions p ON m.medication_id = p.medication_id\nWHERE p.prescription_id IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id.text, citizen_id.text, service_id.text, submitted_at.timestamp, status.text, last_updated_at.timestamp, assigned_employee_id.text, decision_date.date, notes.text, reference_number.text )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "List the full names of citizens who have made payments for services that are currently inactive. Also show the service name and payment amount."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS full_name, s.service_name, p.amount\nFROM government_services.payments p\nJOIN government_services.citizens c ON p.citizen_id = c.citizen_id\nJOIN government_services.services s ON p.service_id = s.service_id\nWHERE s.is_active = FALSE;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n", "conversations": [{"role": "user", "content": "For each scheduled appointment, list the appointment_id, appointment_time, patient_id, and the name of the patient's primary insurance plan. Only include appointments that have not been cancelled."}, {"role": "assistant", "content": "SELECT a.appointment_id,\n a.appointment_time,\n a.patient_id,\n ip.plan_name\nFROM healthcare.appointments a\nJOIN healthcare.patient_insurance pi\n ON a.patient_id = pi.patient_id\n AND pi.is_primary = TRUE\nJOIN healthcare.insurance_plans ip\n ON pi.plan_id = ip.plan_id\nWHERE a.status != 'Cancelled';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n case_id character varying(64) NOT NULL, -- FK to cases table\n document_name character varying(255) NOT NULL, -- name of the document file\n document_type character varying(100), -- e.g., Pleading, Contract, Evidence, Correspondence\n storage_path text NOT NULL, -- path or reference to the document storage location\n uploaded_by_lawyer_id character varying(64), -- FK to lawyers table (who uploaded it)\n upload_timestamp timestamp NOT NULL, -- time the document was uploaded\n version integer DEFAULT 1, -- document version number\n description text, -- brief description or notes about the document\n PRIMARY KEY (document_id)\n)\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n", "conversations": [{"role": "user", "content": "Show each lawyer's first and last name along with the number of open cases they lead, ordered by the highest number of open cases first."}, {"role": "assistant", "content": "SELECT l.first_name, l.last_name, COUNT(c.case_id) AS open_case_count\nFROM legal_services.lawyers l\nJOIN legal_services.cases c\n ON l.lawyer_id = c.lead_lawyer_id\nWHERE c.status = 'Open'\nGROUP BY l.first_name, l.last_name\nORDER BY open_case_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.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.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)\n", "conversations": [{"role": "user", "content": "Show me all available services with a unit of 'Per Hour'."}, {"role": "assistant", "content": "SELECT service_name , description , price FROM hospitality_technology.services WHERE is_available = true AND unit = 'Per Hour'"}, {"role": "user", "content": "Also include the department and filter the results to only show services priced above 100."}, {"role": "assistant", "content": "SELECT service_name , description , price , department FROM hospitality_technology.services WHERE is_available = true AND unit = 'Per Hour' AND price > 100"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\n", "conversations": [{"role": "user", "content": "Could you list each developer along with the next developer founded after them in the same country? Return columns current_developer, next_developer, and years_difference."}, {"role": "assistant", "content": "SELECT d1.name AS current_developer,\n d2.name AS next_developer,\n d2.founded_year - d1.founded_year AS years_difference\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d2.founded_year > d1.founded_year\nWHERE NOT EXISTS (\n SELECT 1\n FROM gaming_technology.developers dx\n WHERE dx.country = d1.country\n AND dx.founded_year > d1.founded_year\n AND dx.founded_year < d2.founded_year\n);\n"}, {"role": "user", "content": "Actually, exclude pairs where the difference is more than 10 years."}, {"role": "assistant", "content": "SELECT d1.name AS current_developer,\n d2.name AS next_developer,\n d2.founded_year - d1.founded_year AS years_difference\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d2.founded_year > d1.founded_year\nWHERE NOT EXISTS (\n SELECT 1\n FROM gaming_technology.developers dx\n WHERE dx.country = d1.country\n AND dx.founded_year > d1.founded_year\n AND dx.founded_year < d2.founded_year\n)\n AND (d2.founded_year - d1.founded_year) <= 10;\n"}, {"role": "user", "content": "Also, only include countries with at least three developers."}, {"role": "assistant", "content": "SELECT d1.name AS current_developer,\n d2.name AS next_developer,\n d2.founded_year - d1.founded_year AS years_difference\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d2.founded_year > d1.founded_year\nWHERE d1.country IN (\n SELECT country\n FROM gaming_technology.developers\n GROUP BY country\n HAVING COUNT(*) >= 3\n)\n AND NOT EXISTS (\n SELECT 1\n FROM gaming_technology.developers dx\n WHERE dx.country = d1.country\n AND dx.founded_year > d1.founded_year\n AND dx.founded_year < d2.founded_year\n )\n AND (d2.founded_year - d1.founded_year) <= 10\nORDER BY d1.country ASC, years_difference ASC;\n"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.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 (\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 ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id text 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 )\n", "conversations": [{"role": "user", "content": "List all maintenance logs for vehicles that had 'Oil Change' service in the last 3 months, showing vehicle ID, service date, and cost."}, {"role": "assistant", "content": "SELECT vehicle_id, service_date, cost FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months';"}, {"role": "user", "content": "Can you include the mechanic name and show only services that cost more than $100?"}, {"role": "assistant", "content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100;"}, {"role": "user", "content": "Actually, I need to see the vehicle make and model as well. Can you include that information?"}, {"role": "assistant", "content": "Sorry, I can't include vehicle make and model as those fields aren't present in the provided table schemas. The maintenance_logs table only contains vehicle_id but not make/model information."}, {"role": "user", "content": "Then just add the odometer reading to the previous query and order by the most recent services first."}, {"role": "assistant", "content": "SELECT vehicle_id, service_date, cost, mechanic_name, odometer_reading FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100 ORDER BY service_date DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.drivers ( driver_id character varying(64) NOT NULL, employee_id character varying(64) NOT NULL UNIQUE, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, license_number character varying(64) NOT NULL UNIQUE, license_expiry_date date NOT NULL, contact_number character varying(32), email character varying(128) UNIQUE, hire_date date NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (driver_id) )\nCREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )\nCREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, name character varying(255) NOT NULL, type character varying(64) NOT NULL, address_line1 character varying(255), city character varying(128), state_province character varying(128), postal_code character varying(32), country character varying(64) NOT NULL, latitude numeric(9, 6), longitude numeric(9, 6), timezone character varying(64), PRIMARY KEY (location_id) )\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\nCREATE TABLE transportation.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) )\n", "conversations": [{"role": "user", "content": "List all trips including the name of the origin location and the name of the destination location."}, {"role": "assistant", "content": "SELECT t.trip_id, origin.name AS origin_location_name, destination.name AS destination_location_name FROM transportation.trips t JOIN transportation.locations origin ON t.origin_location_id = origin.location_id JOIN transportation.locations destination ON t.destination_location_id = destination.location_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n", "conversations": [{"role": "user", "content": "Show me claim IDs and the file names of any documents associated with claims filed before January 1, 2024."}, {"role": "assistant", "content": "SELECT cd.claim_id, cd.file_name\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_id = cd.claim_id\nWHERE c.incident_date < '2024-01-01';"}, {"role": "user", "content": "Only include documents where the file size is less than 1 MB."}, {"role": "assistant", "content": "SELECT cd.claim_id, cd.file_name\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_id = cd.claim_id\nWHERE c.incident_date < '2024-01-01'\n AND cd.file_size_bytes < 1048576;"}, {"role": "user", "content": "Add the document type to the results and sort by file size ascending."}, {"role": "assistant", "content": "SELECT cd.claim_id, cd.file_name, cd.document_type, cd.file_size_bytes\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_id = cd.claim_id\nWHERE c.incident_date < '2024-01-01'\n AND cd.file_size_bytes < 1048576\nORDER BY cd.file_size_bytes ASC;"}, {"role": "user", "content": "Sorry, I got an error about NULL file sizes. Please exclude records where the file size is NULL."}, {"role": "assistant", "content": "SELECT cd.claim_id, cd.file_name, cd.document_type, cd.file_size_bytes\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_id = cd.claim_id\nWHERE c.incident_date < '2024-01-01'\n AND cd.file_size_bytes IS NOT NULL\n AND cd.file_size_bytes < 1048576\nORDER BY cd.file_size_bytes ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "List the username and the total number of notifications each user has received, and also count how many of those are still unread."}, {"role": "assistant", "content": "SELECT u.username,\n COUNT(n.notification_id) AS total_notifications,\n SUM(CASE WHEN n.read_at IS NULL THEN 1 ELSE 0 END) AS unread_notifications\nFROM trading_platform.users u\nLEFT JOIN trading_platform.notifications n\n ON u.user_id = n.user_id\nGROUP BY u.username;"}, {"role": "user", "content": "Actually, limit it to notifications sent in the last 7 days and only show users with at least 1 unread notification."}, {"role": "assistant", "content": "SELECT u.username,\n COUNT(n.notification_id) AS total_notifications,\n SUM(CASE WHEN n.read_at IS NULL THEN 1 ELSE 0 END) AS unread_notifications\nFROM trading_platform.users u\nLEFT JOIN trading_platform.notifications n\n ON u.user_id = n.user_id\n AND n.sent_at >= NOW() - INTERVAL '7 days'\nGROUP BY u.username\nHAVING SUM(CASE WHEN n.read_at IS NULL THEN 1 ELSE 0 END) > 0;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n \"CREATE TABLE project_fundraising_record (\",\n \"id character varying(32) NOT NULL, -- fundraising record id\",\n \"project_id character varying(32) NOT NULL, -- the invested project's id\",\n \"project_name character varying(128) NOT NULL, -- name of the invested project\",\n \"rounds_name character varying(32), -- name of the fundraising round\",\n \"investment_value numeric(38,14), -- amount of the fundraising in USD\",\n \"investment_date character varying(128), -- the date of the investment happened\",\n \"introduction character varying(128), -- the introduction of the invested project\",\n \"valuation numeric(38,14), -- the valuation of the project in USD when invested\",\n\n \"CREATE TABLE token_basic_info (\",\n \"coin_id character varying(100) NOT NULL, -- the id of the token\",\n \"token_name character varying(100) NOT NULL, -- the token's name\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"chain text, -- the chain that the token resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days\",\n \"highest_price_24h double precision, -- the highest price of the token in 24 hours\",\n \"lowest_price_24h double precision, -- the lowest price of the token in 24 hours\",\n \"market_cap double precision, -- the market cap of the token\",\n \"market_cap_rank bigint, -- the rank of the token market cap in desc\",\n \"market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours\",\n \"total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX)\", \n \"narrative text, -- the category or narrative of the token\",\n \"trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (coin_id, chain));\",\n\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\n \"CREATE TABLE token_dexpool_info (\",\n \"pair_address character varying(512) NOT NULL, -- the id of dexpool\",\n \"token_name character varying(100) NOT NULL, -- the name of the token in the dexpool\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"chain text, -- the chain that the dexpool resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"makers_24h double precision, -- the makers of the dex pool in 24 hours\",\n \"volume_24h double precision, -- the trade volume of the dex pool in 24 hours\",\n \"liquidity double precision, -- the liquidity of the dex pool\",\n \"market_cap double precision, -- the market cap of the token\",\n \"trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (pair_address, chain);\"\n\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n \"CREATE TABLE smart_money_profit (\",\n \"address character varying(100) NOT NULL, -- the user's address\",\n \"rank INT, -- the rank of the address in trade performance, value 1 expresses the best address.\",\n \"profit numeric(38,6), -- the profit user made in a month\",\n \"roi numeric(38,2), -- the roi of the user in a month\",\n \"realized_ratio numeric(38,2), -- the percentage of the user's realized profit\",\n \"most_profit_token character varying(100), -- the token symbol of the user's most profitable trade\",\n \"last_trade_time character varying(100), -- the last trade time of the user\",\n \"chain character varying(100), -- the chain that the address resides\",\n \"PRIMARY KEY (address, chain));\",\n\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n", "conversations": [{"role": "user", "content": "List the top 5 tokens by 24 hour trading volume on DEX pools."}, {"role": "assistant", "content": "SELECT token_name, token_symbol, volume_24h \nFROM token_dexpool_info \nORDER BY volume_24h DESC LIMIT 5;"}, {"role": "user", "content": "Show only their token symbols and the related chain, ordered by volume descending."}, {"role": "assistant", "content": "SELECT token_symbol, chain, volume_24h \nFROM token_dexpool_info \nORDER BY volume_24h DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\n", "conversations": [{"role": "user", "content": "Show the usernames and registration dates of all players whose last_login is NULL."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE last_login IS NULL;"}, {"role": "user", "content": "Please also show their country_code, and only include players who registered on or after 2023-01-01."}, {"role": "assistant", "content": "SELECT username, country_code, registration_date FROM gaming_technology.players WHERE last_login IS NULL AND registration_date >= '2023-01-01';"}, {"role": "user", "content": "Also, sort the players by username alphabetically."}, {"role": "assistant", "content": "SELECT username, country_code, registration_date FROM gaming_technology.players WHERE last_login IS NULL AND registration_date >= '2023-01-01' ORDER BY username ASC;"}, {"role": "user", "content": "Add the email field too, and exclude any players whose status is 'banned'."}, {"role": "assistant", "content": "SELECT username, email, country_code, registration_date FROM gaming_technology.players WHERE last_login IS NULL AND registration_date >= '2023-01-01' AND status <> 'banned' ORDER BY username ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "List the top 5 most used services across all properties. Show service_name and total quantity ordered, ordered by quantity descending."}, {"role": "assistant", "content": "SELECT s.service_name,\n SUM(o.quantity) AS total_quantity\nFROM hospitality_technology.services s\nJOIN hospitality_technology.service_orders o ON s.service_id = o.service_id\nGROUP BY s.service_name\nORDER BY total_quantity DESC\nLIMIT 5;"}, {"role": "user", "content": "Now filter those to only include services in the 'Food & Beverage' category and sort by total_quantity descending."}, {"role": "assistant", "content": "SELECT s.service_name,\n SUM(o.quantity) AS total_quantity\nFROM hospitality_technology.services s\nJOIN hospitality_technology.service_orders o ON s.service_id = o.service_id\nWHERE s.category = 'Food & Beverage'\nGROUP BY s.service_name\nORDER BY total_quantity DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\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 the names of properties and the room number for every room at each property."}, {"role": "assistant", "content": "SELECT T1.property_name , T2.room_number FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.rooms AS T2 ON T1.property_id = T2.property_id"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id uuid, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\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, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid, player_id uuid, item_id uuid, quantity integer, acquired_at timestamp with time zone, instance_data jsonb )\n", "conversations": [{"role": "user", "content": "I\u2019d like to see how many achievements each player has unlocked and the date of their first unlock."}, {"role": "assistant", "content": "SELECT pa.player_id, COUNT(pa.achievement_id) AS achievement_count, MIN(pa.unlocked_at) AS first_unlocked\nFROM gaming_technology.player_achievements pa\nGROUP BY pa.player_id;"}, {"role": "user", "content": "Actually, exclude players with fewer than 3 achievements and only consider achievements worth at least 10 points."}, {"role": "assistant", "content": "SELECT pa.player_id, COUNT(pa.achievement_id) AS achievement_count, MIN(pa.unlocked_at) AS first_unlocked\nFROM gaming_technology.player_achievements pa\nJOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id\nWHERE a.points >= 10\nGROUP BY pa.player_id\nHAVING COUNT(pa.achievement_id) >= 3;"}, {"role": "user", "content": "Also include the title of the game for the earliest unlocked achievement."}, {"role": "assistant", "content": "SELECT x.player_id, x.achievement_count, x.first_unlocked, g.title AS game_title\nFROM (\n SELECT pa.player_id,\n COUNT(pa.achievement_id) AS achievement_count,\n MIN(pa.unlocked_at) AS first_unlocked\n FROM gaming_technology.player_achievements pa\n JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id\n WHERE a.points >= 10\n GROUP BY pa.player_id\n HAVING COUNT(pa.achievement_id) >= 3\n) x\nJOIN gaming_technology.player_achievements pa2 \n ON x.player_id = pa2.player_id AND x.first_unlocked = pa2.unlocked_at\nJOIN gaming_technology.achievements a2 \n ON pa2.achievement_id = a2.achievement_id\nJOIN gaming_technology.games g \n ON a2.game_id = g.game_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text )\nCREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\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 maintenance logs for vehicles assigned to depots in 'Los Angeles'. For each log, list the log_id, vehicle_id, service_date, and depot name."}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, loc.name AS depot_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nJOIN transportation.locations loc ON v.depot_id = loc.location_id\nWHERE loc.city = 'Los Angeles';"}, {"role": "user", "content": "Can you also include the maintenance cost and the mechanic's name?"}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, loc.name AS depot_name, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nJOIN transportation.locations loc ON v.depot_id = loc.location_id\nWHERE loc.city = 'Los Angeles';"}, {"role": "user", "content": "Filter to only include logs where the cost is greater than 500."}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, loc.name AS depot_name, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nJOIN transportation.locations loc ON v.depot_id = loc.location_id\nWHERE loc.city = 'Los Angeles'\n AND ml.cost > 500;"}, {"role": "user", "content": "I got an error about 'loc.name' not being unique. Can you also include the depot_id in the select statement?"}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, v.depot_id, loc.name AS depot_name, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nJOIN transportation.locations loc ON v.depot_id = loc.location_id\nWHERE loc.city = 'Los Angeles'\n AND ml.cost > 500;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\nCREATE TABLE insurance.policies (\n policy_id character varying(64) NOT NULL, -- unique identifier for the policy\n customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)\n product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)\n agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)\n policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number\n start_date date NOT NULL, -- date the policy coverage begins\n end_date date NOT NULL, -- date the policy coverage ends\n premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term\n coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered\n deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in\n status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending\n issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued\n cancellation_date date,\n cancellation_reason text,\n PRIMARY KEY (policy_id)\n)\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.agents ( agent_id.text, first_name.text, last_name.text, agency_name.text, license_number.text, license_state.text, contact_email.text, contact_phone.text, hire_date.date, termination_date.date, status.text, commission_rate.numeric, manager_id.text )\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\n", "conversations": [{"role": "user", "content": "Show the total number of policies in each status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM insurance.policies GROUP BY status"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 all trips with their trip ID, route ID, the ID of their origin location, and the ID of their destination location, where the route ID starts with 'EX'."}, {"role": "assistant", "content": "SELECT trip_id, route_id, origin_location_id, destination_location_id FROM transportation.trips WHERE route_id LIKE 'EX%';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers ( driver_id 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.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\nCREATE TABLE transportation.passengers (\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": "Can you list the email addresses, full names, and loyalty program IDs of all passengers who joined in March 2024?"}, {"role": "assistant", "content": "SELECT email, first_name, last_name, loyalty_program_id FROM transportation.passengers WHERE DATE_TRUNC('month', created_at) = DATE '2024-03-01';"}, {"role": "user", "content": "Please only show passengers who have a loyalty_program_id and sort by last name ascending."}, {"role": "assistant", "content": "SELECT email, first_name, last_name, loyalty_program_id FROM transportation.passengers WHERE DATE_TRUNC('month', created_at) = DATE '2024-03-01' AND loyalty_program_id IS NOT NULL ORDER BY last_name ASC;"}, {"role": "user", "content": "Now also include their date_of_birth in the result, and only show those born after 1995."}, {"role": "assistant", "content": "SELECT email, first_name, last_name, loyalty_program_id, date_of_birth FROM transportation.passengers WHERE DATE_TRUNC('month', created_at) = DATE '2024-03-01' AND loyalty_program_id IS NOT NULL AND date_of_birth > DATE '1995-12-31' ORDER BY last_name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.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": "Find all pairs of patients who share the same emergency_contact_name. Show patient IDs and the shared emergency contact name."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p2.patient_id AS patient2_id, p1.emergency_contact_name\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_name = p2.emergency_contact_name\n AND p1.patient_id < p2.patient_id;"}, {"role": "user", "content": "Actually, exclude any rows where emergency_contact_name is NULL or an empty string."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p2.patient_id AS patient2_id, p1.emergency_contact_name\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_name = p2.emergency_contact_name\n AND p1.patient_id < p2.patient_id\nWHERE p1.emergency_contact_name IS NOT NULL\n AND p1.emergency_contact_name <> '';"}, {"role": "user", "content": "Also, sort the results by emergency_contact_name ascending and then by patient1_id."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p2.patient_id AS patient2_id, p1.emergency_contact_name\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_name = p2.emergency_contact_name\n AND p1.patient_id < p2.patient_id\nWHERE p1.emergency_contact_name IS NOT NULL\n AND p1.emergency_contact_name <> ''\nORDER BY p1.emergency_contact_name ASC, p1.patient_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.blocks (\n block_id character varying(64) NOT NULL, -- unique identifier for the block\n previous_block_id character varying(64), -- identifier of the previous block\n timestamp timestamp NOT NULL, -- time when the block was mined\n nonce integer NOT NULL, -- nonce value used in the proof of work\n merkle_root character varying(128) NOT NULL, -- root of the Merkle tree for transactions\n difficulty integer NOT NULL, -- difficulty level of the block\n PRIMARY KEY (block_id)\n)\n", "conversations": [{"role": "user", "content": "Retrieve the block ID, timestamp, current block's difficulty, and the difficulty of the *previous* block for all blocks where the current block's difficulty is strictly greater than the previous block's difficulty."}, {"role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b1.difficulty AS current_difficulty, b2.difficulty AS previous_difficulty FROM blockchain.blocks b1 JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id WHERE b1.difficulty > b2.difficulty;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "List service orders including the order ID, service ID, quantity, total price, status, and the full name of the staff member who placed the order."}, {"role": "assistant", "content": "SELECT T1.order_id, T1.service_id, T1.quantity, T1.total_price, T1.status, T2.first_name, T2.last_name FROM hospitality_technology.service_orders AS T1 JOIN hospitality_technology.staff AS T2 ON T1.staff_id_ordered = T2.staff_id;"}, {"role": "user", "content": "Filter these orders to only show those with a status of 'InProgress' or 'Pending' and order them by the order timestamp."}, {"role": "assistant", "content": "SELECT T1.order_id, T1.service_id, T1.quantity, T1.total_price, T1.status, T2.first_name, T2.last_name FROM hospitality_technology.service_orders AS T1 JOIN hospitality_technology.staff AS T2 ON T1.staff_id_ordered = T2.staff_id WHERE T1.status IN ('InProgress', 'Pending') ORDER BY T1.order_timestamp;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of users who have different usernames but share the same username length. List both user IDs, usernames, and the shared username length."}, {"role": "assistant", "content": "SELECT u1.user_id, u1.username AS user1_username, u2.user_id, u2.username AS user2_username, LENGTH(u1.username) AS username_length FROM web3.users u1 JOIN web3.users u2 ON LENGTH(u1.username) = LENGTH(u2.username) AND u1.user_id < u2.user_id WHERE u1.username <> u2.username;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n", "conversations": [{"role": "user", "content": "For each player, list their username and the total number of unique servers they have played on, only including players who have played on two or more different servers. Also show the titles of all games they've played sessions on."}, {"role": "assistant", "content": "SELECT p.username, COUNT(DISTINCT gs.server_id) AS unique_servers, STRING_AGG(DISTINCT g.title, ', ') AS game_titles\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nJOIN gaming_technology.servers s ON gs.server_id = s.server_id\nJOIN gaming_technology.games g ON gs.game_id = g.game_id\nWHERE gs.server_id IS NOT NULL\nGROUP BY p.player_id\nHAVING COUNT(DISTINCT gs.server_id) >= 2;"}, {"role": "user", "content": "Add another column for the total duration in seconds that each player has spent on these servers."}, {"role": "assistant", "content": "SELECT p.username, COUNT(DISTINCT gs.server_id) AS unique_servers, STRING_AGG(DISTINCT g.title, ', ') AS game_titles, SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nJOIN gaming_technology.servers s ON gs.server_id = s.server_id\nJOIN gaming_technology.games g ON gs.game_id = g.game_id\nWHERE gs.server_id IS NOT NULL\nGROUP BY p.player_id\nHAVING COUNT(DISTINCT gs.server_id) >= 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.maintenance_logs ( log_id 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": "Show me all maintenance logs that do not have a next service due date recorded. List the log ID, vehicle ID, and service date."}, {"role": "assistant", "content": "SELECT log_id, vehicle_id, service_date FROM transportation.maintenance_logs WHERE next_service_due_date IS NULL;"}, {"role": "user", "content": "For these logs with no next service date, please also include the description and the cost, and sort the results by service date descending."}, {"role": "assistant", "content": "SELECT log_id, vehicle_id, service_date, description, cost FROM transportation.maintenance_logs WHERE next_service_due_date IS NULL ORDER BY service_date DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars (\n car_id character varying(64) NOT NULL, -- Unique identifier for the train car\n train_id character varying(64) NOT NULL, -- Foreign key referencing trains\n car_number character varying(10) NOT NULL, -- Identifier of the car within the train set\n car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage\n class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars)\n capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars)\n features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom')\n PRIMARY KEY (car_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id)\n)\nCREATE TABLE train_station_management.routes (\n route_id character varying(64) NOT NULL, -- Unique identifier for the route\n route_name character varying(128) NOT NULL, -- Name of the route (e.g., 'Northeast Corridor')\n description text, -- Description of the route\n origin_station_id character varying(64) NOT NULL, -- Starting station\n destination_station_id character varying(64) NOT NULL, -- Final station\n is_active boolean NOT NULL DEFAULT true, -- Is the route currently operational?\n PRIMARY KEY (route_id),\n FOREIGN KEY (origin_station_id) REFERENCES train_station_management.stations(station_id),\n FOREIGN KEY (destination_station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.tickets (\n ticket_id character varying(64) NOT NULL, -- Unique identifier for the ticket\n booking_id character varying(64) NOT NULL, -- Foreign key referencing the booking\n car_id character varying(64) NOT NULL, -- Foreign key referencing the train car\n seat_number character varying(10), -- Assigned seat number (e.g., '12A')\n ticket_type character varying(32) NOT NULL DEFAULT 'Adult', -- e.g., Adult, Child, Senior, Student\n price numeric(10, 2) NOT NULL, -- Price of this specific ticket\n is_checked_in boolean NOT NULL DEFAULT false, -- Has the passenger checked in with this ticket?\n qr_code_data text, -- Data for generating a QR code for the ticket\n PRIMARY KEY (ticket_id),\n FOREIGN KEY (booking_id) REFERENCES train_station_management.bookings(booking_id),\n FOREIGN KEY (car_id) REFERENCES train_station_management.train_cars(car_id)\n)\n", "conversations": [{"role": "user", "content": "I need to find all tickets for a specific route 'RT456' along with the car details and route information."}, {"role": "assistant", "content": "SELECT t.ticket_id, t.seat_number, t.price, tc.car_number, tc.car_type, r.route_name, r.description\nFROM train_station_management.tickets t\nJOIN train_station_management.train_cars tc ON t.car_id = tc.car_id\nJOIN train_station_management.trains tr ON tc.train_id = tr.train_id\nJOIN train_station_management.routes r ON tr.route_id = r.route_id\nWHERE r.route_id = 'RT456';"}, {"role": "user", "content": "Can you filter this to show only tickets that have been checked in?"}, {"role": "assistant", "content": "SELECT t.ticket_id, t.seat_number, t.price, tc.car_number, tc.car_type, r.route_name, r.description\nFROM train_station_management.tickets t\nJOIN train_station_management.train_cars tc ON t.car_id = tc.car_id\nJOIN train_station_management.trains tr ON tc.train_id = tr.train_id\nJOIN train_station_management.routes r ON tr.route_id = r.route_id\nWHERE r.route_id = 'RT456' AND t.is_checked_in = true;"}, {"role": "user", "content": "Can you also add the ticket type to the results?"}, {"role": "assistant", "content": "SELECT t.ticket_id, t.seat_number, t.price, t.ticket_type, tc.car_number, tc.car_type, r.route_name, r.description\nFROM train_station_management.tickets t\nJOIN train_station_management.train_cars tc ON t.car_id = tc.car_id\nJOIN train_station_management.trains tr ON tc.train_id = tr.train_id\nJOIN train_station_management.routes r ON tr.route_id = r.route_id\nWHERE r.route_id = 'RT456' AND t.is_checked_in = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "Show me medical records that mention a medication from the 'medications' table by name in their treatment plan. List the record ID, record date, patient ID, and the name of the mentioned medication."}, {"role": "assistant", "content": "SELECT T1.record_id, T1.record_date, T1.patient_id, T2.medication_name FROM healthcare.medical_records AS T1 JOIN healthcare.medications AS T2 ON T1.treatment_plan LIKE '%' || T2.medication_name || '%' WHERE T2.medication_name IS NOT NULL AND T2.medication_name != ''"}, {"role": "user", "content": "Add the doctor ID who created the record and the manufacturer of the medication to the results."}, {"role": "assistant", "content": "SELECT T1.record_id, T1.record_date, T1.patient_id, T2.medication_name, T1.doctor_id, T2.manufacturer FROM healthcare.medical_records AS T1 JOIN healthcare.medications AS T2 ON T1.treatment_plan LIKE '%' || T2.medication_name || '%' WHERE T2.medication_name IS NOT NULL AND T2.medication_name != ''"}, {"role": "user", "content": "Filter these results to only include records created after January 1st, 2023, and sort by record date ascending."}, {"role": "assistant", "content": "SELECT T1.record_id, T1.record_date, T1.patient_id, T2.medication_name, T1.doctor_id, T2.manufacturer FROM healthcare.medical_records AS T1 JOIN healthcare.medications AS T2 ON T1.treatment_plan LIKE '%' || T2.medication_name || '%' WHERE T2.medication_name IS NOT NULL AND T2.medication_name != '' AND T1.created_at > '2023-01-01' ORDER BY T1.record_date ASC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n// Use Hashes to store station details. Key format: station:\n// Example:\n// HSET station:station_xyz station_id \"station_xyz\" station_name \"Grand Central Terminal\" city \"New York\" state_province \"NY\" country_code \"USA\" address \"89 E 42nd St...\" timezone \"America/New_York\" number_of_platforms 44 created_at \"2023-01-15T10:00:00Z\" last_updated_at \"2023-10-28T15:30:00Z\"\n\n// To quickly find stations by city (optional index):\n// SADD stations:city:NewYork station:station_xyz\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 route details. Key format: route:\n// HSET route:route_ne_corr route_id \"route_ne_corr\" route_name \"Northeast Corridor\" ... origin_station_id \"station_bos\" ... is_active 1\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 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", "conversations": [{"role": "user", "content": "\u80fd\u5426\u5e2e\u6211\u67e5\u8be2\u7279\u5b9a\u5217\u8f66(train_id \u4e3a 'train_789')\u4e0a\u7684\u6240\u6709\u8f66\u8f86\u4fe1\u606f\uff0c\u5e76\u5173\u8054\u5230\u8be5\u5217\u8f66\u6240\u5728\u7684\u8def\u7ebf\u4fe1\u606f\uff1f"}, {"role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car: for each car_id in result\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking: for each booking_id in result\nHGETALL route: for route_id associated with schedule"}, {"role": "user", "content": "\u80fd\u5426\u5c06\u67e5\u8be2\u7ed3\u679c\u9650\u5236\u5728\u8f66\u8f86\u7c7b\u578b\u4e3a\u2018Passenger\u2019\u7684\u8f66\u8f86\u4e0a\uff1f"}, {"role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car: for each car_id in result where car_type='Passenger'\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking: for each booking_id in result\nHGETALL route: for route_id associated with schedule"}, {"role": "user", "content": "\u80fd\u5426\u518d\u52a0\u5165\u8f66\u8f86\u7684\u5ea7\u4f4d\u5bb9\u91cf\u4fe1\u606f\uff0c\u5e76\u6309\u7167\u5bb9\u91cf\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff1f"}, {"role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car: for each car_id in result where car_type='Passenger'\nSORT car: BY capacity DESC\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking: for each booking_id in result\nHGETALL route: for route_id associated with schedule"}, {"role": "user", "content": "\u80fd\u5426\u4e5f\u628a\u8def\u7ebf\u7684\u8d77\u70b9\u7ad9\u548c\u7ec8\u70b9\u7ad9\u4fe1\u606f\u52a0\u5165\u5230\u7ed3\u679c\u4e2d\uff1f"}, {"role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car: for each car_id in result where car_type='Passenger'\nSORT car: BY capacity DESC\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking: for each booking_id in result\nHGETALL route: for route_id associated with schedule\nZRANGE route::stops 0 0 for origin_station_id\nZRANGE route::stops -1 -1 for destination_station_id\nHGETALL station:\nHGETALL station:"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text PRIMARY KEY, property_id text, room_number text, room_type_id text, floor int, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text PRIMARY KEY, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "List the names of properties and the number of services they offer in the 'Spa' department."}, {"role": "assistant", "content": "SELECT P.property_name, COUNT(S.service_id) AS spa_service_count FROM hospitality_technology.properties AS P JOIN hospitality_technology.services AS S ON P.property_id = S.property_id WHERE S.department = 'Spa' GROUP BY P.property_id, P.property_name;"}, {"role": "user", "content": "Only show properties that offer more than 2 'Spa' services."}, {"role": "assistant", "content": "SELECT P.property_name, COUNT(S.service_id) AS spa_service_count FROM hospitality_technology.properties AS P JOIN hospitality_technology.services AS S ON P.property_id = S.property_id WHERE S.department = 'Spa' GROUP BY P.property_id, P.property_name HAVING COUNT(S.service_id) > 2;"}, {"role": "user", "content": "Instead of the count, can you show me the average price of 'Spa' services for those properties, along with the property name?"}, {"role": "assistant", "content": "SELECT P.property_name, AVG(S.price) AS average_spa_price FROM hospitality_technology.properties AS P JOIN hospitality_technology.services AS S ON P.property_id = S.property_id WHERE S.department = 'Spa' GROUP BY P.property_id, P.property_name HAVING COUNT(S.service_id) > 2;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id text, model_name text, manufacturer text, passenger_capacity integer, max_range_km integer, engine_type text, wingspan_m numeric, status text, first_flight_date date )\n", "conversations": [{"role": "user", "content": "What are the 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List all posts along with the user emails of the authors."}, {"role": "assistant", "content": "SELECT p.post_id, p.content, u.email\nFROM social_media.posts p\nJOIN social_media.users u ON p.user_id = u.user_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\n", "conversations": [{"role": "user", "content": "I need a list of all group chat names with every username."}, {"role": "assistant", "content": "SELECT u.username, c.group_name\nFROM social_media.users u\nJOIN social_media.conversations c ON 1=1\nWHERE c.is_group_chat = true;"}, {"role": "user", "content": "Actually, only include users who are verified."}, {"role": "assistant", "content": "SELECT u.username, c.group_name\nFROM social_media.users u\nJOIN social_media.conversations c ON 1=1\nWHERE c.is_group_chat = true\n AND u.is_verified = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.agents ( agent_id text, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.premium_payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment\n policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)\n payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received\n amount_paid numeric(12, 2) NOT NULL, -- amount of the payment\n payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check\n transaction_reference character varying(128) UNIQUE, -- reference from payment processor\n due_date date, -- due date for this payment installment\n payment_period_start date, -- start date of the period this payment covers\n payment_period_end date, -- end date of the period this payment covers\n status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded\n PRIMARY KEY (payment_id)\n)\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n", "conversations": [{"role": "user", "content": "Show me each payment_method and the number of premium payments made using that method, sorted by the count in descending order."}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count FROM insurance.premium_payments GROUP BY payment_method ORDER BY payment_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.accounts (\n account_id character varying(64) NOT NULL, -- unique identifier for the account\n customer_id character varying(64) NOT NULL, -- foreign key linking to the customer\n account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer\n account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card\n balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance\n currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR)\n opened_date date NOT NULL, -- date the account was opened\n status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen\n interest_rate numeric(5, 4), -- annual interest rate, if applicable\n last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update\n PRIMARY KEY (account_id),\n FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id)\n)\n", "conversations": [{"role": "user", "content": "Summarize the accounts table by account type and currency, showing the average balance for each combination."}, {"role": "assistant", "content": "SELECT account_type, currency, AVG(balance) AS average_balance, COUNT(account_id) AS account_count FROM financial_services.accounts GROUP BY account_type, currency ORDER BY account_type, currency;"}, {"role": "user", "content": "Only include combinations where the average balance is greater than 5000."}, {"role": "assistant", "content": "SELECT account_type, currency, AVG(balance) AS average_balance, COUNT(account_id) AS account_count FROM financial_services.accounts GROUP BY account_type, currency HAVING AVG(balance) > 5000 ORDER BY average_balance DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text, transaction_id text, output_index integer, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.peers ( peer_id text, ip_address text, port integer, last_seen timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the top 5 users who have the highest total trade volume (quantity * price) as buyers, along with their email addresses and the number of distinct assets they traded."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(DISTINCT t.asset_id) AS distinct_assets_traded, SUM(t.quantity * t.price) AS total_trade_volume FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id GROUP BY u.user_id, u.email ORDER BY total_trade_volume DESC LIMIT 5;"}, {"role": "user", "content": "Now modify the query to include only trades that happened in the last 30 days and show the average trade price for each buyer."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(DISTINCT t.asset_id) AS distinct_assets_traded, SUM(t.quantity * t.price) AS total_trade_volume, AVG(t.price) AS average_trade_price FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY u.user_id, u.email ORDER BY total_trade_volume DESC LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the top 5 buyers by total trade volume who also have wallets, and include their wallet addresses."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, w.address AS wallet_address, SUM(t.quantity * t.price) AS total_trade_volume FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id JOIN trading_platform.orders o ON t.order_id = o.order_id JOIN trading_platform.utxos w ON o.wallet_id = w.address WHERE w.spent = false GROUP BY u.user_id, u.email, w.address ORDER BY total_trade_volume DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\n", "conversations": [{"role": "user", "content": "For each agency, how many services are currently inactive? Return the agency_id and the count of inactive services."}, {"role": "assistant", "content": "SELECT\n agency_id,\n COUNT(*) AS inactive_service_count\nFROM government_services.services\nWHERE is_active = FALSE\nGROUP BY agency_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE 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_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": "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.1."}, {"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.1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "I think there's an error in your query - it should be 'tpl.symbol' not 'tm.symbol'. Also, can you add the decimals to the results?"}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.decimals, tm.total_supply, tpl.symbol, 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.1 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.contract_address, tm.decimals, tm.total_supply, tpl.symbol, 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.1 AND tm.decimals = 18 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.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.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Please provide a list of all driver and passenger pairs who were hired and registered on the same date. Show the driver's full name, the passenger's full name, and the shared date."}, {"role": "assistant", "content": "SELECT d.first_name AS driver_first_name, d.last_name AS driver_last_name, p.first_name AS passenger_first_name, p.last_name AS passenger_last_name, d.hire_date AS shared_date\nFROM transportation.drivers d\nJOIN transportation.passengers p ON d.hire_date = DATE(p.created_at);"}, {"role": "user", "content": "Actually, I only want to see pairs where the passenger's email is present and the driver's status is 'Active'."}, {"role": "assistant", "content": "SELECT d.first_name AS driver_first_name, d.last_name AS driver_last_name, p.first_name AS passenger_first_name, p.last_name AS passenger_last_name, d.hire_date AS shared_date\nFROM transportation.drivers d\nJOIN transportation.passengers p ON d.hire_date = DATE(p.created_at)\nWHERE p.email IS NOT NULL AND d.status = 'Active';"}, {"role": "user", "content": "One more change: only include results where the shared date is in the year 2024."}, {"role": "assistant", "content": "SELECT d.first_name AS driver_first_name, d.last_name AS driver_last_name, p.first_name AS passenger_first_name, p.last_name AS passenger_last_name, d.hire_date AS shared_date\nFROM transportation.drivers d\nJOIN transportation.passengers p ON d.hire_date = DATE(p.created_at)\nWHERE p.email IS NOT NULL AND d.status = 'Active' AND EXTRACT(YEAR FROM d.hire_date) = 2024;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n", "conversations": [{"role": "user", "content": "List all service orders showing the order ID, service ID, quantity, and total price."}, {"role": "assistant", "content": "SELECT order_id, service_id, quantity, total_price FROM hospitality_technology.service_orders LIMIT 100;"}, {"role": "user", "content": "Only show orders with a status of 'Delivered' and sort by total price descending."}, {"role": "assistant", "content": "SELECT order_id, service_id, quantity, total_price FROM hospitality_technology.service_orders WHERE status = 'Delivered' ORDER BY total_price DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\n", "conversations": [{"role": "user", "content": "Show the event_id, transaction_id, and emitted_at timestamp for all events with event_name 'Approval' and contract_id '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'."}, {"role": "assistant", "content": "SELECT event_id, transaction_id, emitted_at FROM web3.events WHERE event_name = 'Approval' AND contract_id = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.time_entries ( entry_id text, 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": "List total billable hours and total amount per lawyer for July 2023."}, {"role": "assistant", "content": "SELECT lawyer_id,\n SUM(hours_spent) AS total_hours,\n SUM(hours_spent * billing_rate) AS total_amount\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND date_worked BETWEEN '2023-07-01' AND '2023-07-31'\nGROUP BY lawyer_id;"}, {"role": "user", "content": "Actually, only include lawyers who logged more than 40 billable hours that month."}, {"role": "assistant", "content": "SELECT lawyer_id,\n SUM(hours_spent) AS total_hours,\n SUM(hours_spent * billing_rate) AS total_amount\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND date_worked BETWEEN '2023-07-01' AND '2023-07-31'\nGROUP BY lawyer_id\nHAVING SUM(hours_spent) > 40;"}, {"role": "user", "content": "Also show the average billing rate for each of those lawyers."}, {"role": "assistant", "content": "SELECT lawyer_id,\n SUM(hours_spent) AS total_hours,\n SUM(hours_spent * billing_rate) AS total_amount,\n AVG(billing_rate) AS avg_rate\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND date_worked BETWEEN '2023-07-01' AND '2023-07-31'\nGROUP BY lawyer_id\nHAVING SUM(hours_spent) > 40;"}, {"role": "user", "content": "Finally, order the results by total_amount descending."}, {"role": "assistant", "content": "SELECT lawyer_id,\n SUM(hours_spent) AS total_hours,\n SUM(hours_spent * billing_rate) AS total_amount,\n AVG(billing_rate) AS avg_rate\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND date_worked BETWEEN '2023-07-01' AND '2023-07-31'\nGROUP BY lawyer_id\nHAVING SUM(hours_spent) > 40\nORDER BY total_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the list of guests who were created in 2024, along with their first and last names and registration date."}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, created_at FROM hospitality_technology.guests WHERE EXTRACT(YEAR FROM created_at) = 2024;"}, {"role": "user", "content": "Please filter this list to include only those who have a loyalty member ID."}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, created_at FROM hospitality_technology.guests WHERE EXTRACT(YEAR FROM created_at) = 2024 AND loyalty_member_id IS NOT NULL AND loyalty_member_id <> '';"}, {"role": "user", "content": "Also show their email and date of birth."}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, email, date_of_birth, created_at FROM hospitality_technology.guests WHERE EXTRACT(YEAR FROM created_at) = 2024 AND loyalty_member_id IS NOT NULL AND loyalty_member_id <> '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "How many appointments have a status of 'Cancelled'?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM legal_services.appointments WHERE status = 'Cancelled';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\nCREATE TABLE government_services.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.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "For each citizen who has at least one document pending verification and at least one appointment not completed, display the citizen's full name, the document type, the document's upload timestamp, the appointment ID, and the appointment status."}, {"role": "assistant", "content": "SELECT c.citizen_id,\n c.first_name || ' ' || c.last_name AS full_name,\n d.document_type,\n d.upload_timestamp,\n a.appointment_id,\n a.status\nFROM government_services.citizens c\nJOIN government_services.documents d ON c.citizen_id = d.citizen_id\nJOIN government_services.appointments a ON c.citizen_id = a.citizen_id\nWHERE d.verification_status = 'Pending'\n AND a.status <> 'Completed';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers ( driver_id 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.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\nCREATE TABLE transportation.passengers (\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": "For all maintenance records, can you show the vehicle's make, model, the odometer reading, and the mechanic's name?"}, {"role": "assistant", "content": "SELECT v.make, v.model, m.odometer_reading, m.mechanic_name FROM transportation.maintenance_logs m JOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id;"}, {"role": "user", "content": "Instead of all maintenance records, only show the ones where the maintenance cost is greater than 1000 and sort by cost descending."}, {"role": "assistant", "content": "SELECT v.make, v.model, m.odometer_reading, m.mechanic_name FROM transportation.maintenance_logs m JOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id WHERE m.cost > 1000 ORDER BY m.cost DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n", "conversations": [{"role": "user", "content": "For each property, show the property_name, the total number of available services, and the average price of those services."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(s.service_id) AS total_available_services,\n AVG(s.price) AS avg_service_price\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.services s ON s.property_id = p.property_id\nWHERE s.is_available = TRUE\nGROUP BY p.property_name;"}, {"role": "user", "content": "Now exclude properties that have zero available services and only include those with an average price greater than 50."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(s.service_id) AS total_available_services,\n AVG(s.price) AS avg_service_price\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.services s ON s.property_id = p.property_id\nWHERE s.is_available = TRUE\nGROUP BY p.property_name\nHAVING COUNT(s.service_id) > 0\n AND AVG(s.price) > 50;"}, {"role": "user", "content": "Also, restrict the services to only those in the 'Wellness' and 'Spa' departments."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(s.service_id) AS total_available_services,\n AVG(s.price) AS avg_service_price\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.services s ON s.property_id = p.property_id\nWHERE s.is_available = TRUE\n AND s.department IN ('Wellness', 'Spa')\nGROUP BY p.property_name\nHAVING COUNT(s.service_id) > 0\n AND AVG(s.price) > 50;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 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 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_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": "Which wallets currently hold more than 200 units of any ERC1155 NFT, and what is the token ID and contract address for each such holding?"}, {"role": "assistant", "content": "SELECT contract_address, token_id, wallet_address, amount FROM nft_holders WHERE contract_type = 'ERC1155' AND CAST(amount AS INTEGER) > 200;"}, {"role": "user", "content": "Can you also add the collection name for each NFT by joining with the nft_metadata table?"}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, nh.wallet_address, nh.amount, nm.contract_name AS collection_name FROM nft_holders nh LEFT 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 INTEGER) > 200;"}, {"role": "user", "content": "Only include results where the contract type is 'ERC1155' and the collection's deploy_block_number is after 13000000."}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, nh.wallet_address, nh.amount, nm.contract_name AS collection_name FROM nft_holders nh LEFT 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 INTEGER) > 200 AND nm.mint_block_number > 13000000;"}, {"role": "user", "content": "Add the rarity score for each NFT from nft_metadata and order the results by rarity_score descending, limit to top 10."}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, nh.wallet_address, nh.amount, nm.contract_name AS collection_name, nm.rarity_score FROM nft_holders nh LEFT 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 INTEGER) > 200 AND nm.mint_block_number > 13000000 ORDER BY nm.rarity_score DESC LIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 top 5 users with the most KYC audits, along with their latest audit status."}, {"role": "assistant", "content": "SELECT user_id, status, COUNT(*) as audit_count FROM trading_platform.kyc_audit GROUP BY user_id, status ORDER BY audit_count DESC LIMIT 5;"}, {"role": "user", "content": "Now modify the query to show only users whose latest KYC status was rejected."}, {"role": "assistant", "content": "WITH latest_audit AS (SELECT user_id, status, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY reviewed_at DESC) as rn FROM trading_platform.kyc_audit) SELECT user_id, status FROM latest_audit WHERE rn = 1 AND status = 'rejected' LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the count of rejected audits per user instead of just the latest status."}, {"role": "assistant", "content": "SELECT user_id, COUNT(*) as rejected_count FROM trading_platform.kyc_audit WHERE status = 'rejected' GROUP BY user_id ORDER BY rejected_count DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\n", "conversations": [{"role": "user", "content": "Show me the usernames of users who have the word 'explorer' in their bio."}, {"role": "assistant", "content": "SELECT username\nFROM social_media.users\nWHERE bio ILIKE '%explorer%';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_id) )\nCREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n", "conversations": [{"role": "user", "content": "Count the number of servers for each possible status recorded in the servers table."}, {"role": "assistant", "content": "SELECT status, COUNT(server_id) AS server_count FROM gaming_technology.servers GROUP BY status;"}, {"role": "user", "content": "Only include statuses where the server count is greater than 5."}, {"role": "assistant", "content": "SELECT status, COUNT(server_id) AS server_count FROM gaming_technology.servers GROUP BY status HAVING COUNT(server_id) > 5;"}, {"role": "user", "content": "For those filtered statuses, calculate the total number of current players across the servers in each status group."}, {"role": "assistant", "content": "SELECT status, COUNT(server_id) AS server_count, SUM(current_players) AS total_current_players FROM gaming_technology.servers GROUP BY status HAVING COUNT(server_id) > 5;"}, {"role": "user", "content": "Order the results by the total current players in descending order."}, {"role": "assistant", "content": "SELECT status, COUNT(server_id) AS server_count, SUM(current_players) AS total_current_players FROM gaming_technology.servers GROUP BY status HAVING COUNT(server_id) > 5 ORDER BY total_current_players DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List reservations, including the reservation ID, check-in date, check-out date, property name, room type name, and room type base rate, for reservations with 3 or more adults."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T1.check_in_date, T1.check_out_date, T2.property_name, T3.type_name, T3.base_rate FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.room_types AS T3 ON T1.room_type_id = T3.room_type_id WHERE T1.num_adults >= 3;"}, {"role": "user", "content": "Now, only include reservations made at properties with a star rating of 4 or higher and sort the results by check-in date."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T1.check_in_date, T1.check_out_date, T2.property_name, T3.type_name, T3.base_rate FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.room_types AS T3 ON T1.room_type_id = T3.room_type_id WHERE T1.num_adults >= 3 AND T2.star_rating >= 4 ORDER BY T1.check_in_date;"}, {"role": "user", "content": "Further refine this list to include only reservations where the total amount is over 700, and limit the results to the top 15."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T1.check_in_date, T1.check_out_date, T2.property_name, T3.type_name, T3.base_rate FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.room_types AS T3 ON T1.room_type_id = T3.room_type_id WHERE T1.num_adults >= 3 AND T2.star_rating >= 4 AND T1.total_amount > 700 ORDER BY T1.check_in_date LIMIT 15;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\nCREATE TABLE web3.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.token_transfers ( transfer_id character varying(64) NOT NULL, token_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128) NOT NULL, value numeric(38,14) NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (transfer_id) )\nCREATE TABLE web3.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\n", "conversations": [{"role": "user", "content": "For each deployer address, show the total supply of all tokens created by the contracts they deployed."}, {"role": "assistant", "content": "SELECT c.deployer_address, SUM(t.total_supply) AS total_token_supply\nFROM web3.contracts c\nJOIN web3.tokens t ON c.address = t.contract_address\nGROUP BY c.deployer_address;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )\n", "conversations": [{"role": "user", "content": "Find consecutive pairs of trips for each vehicle based on the scheduled departure time."}, {"role": "assistant", "content": "WITH RankedTrips AS (\n SELECT\n trip_id,\n vehicle_id,\n scheduled_departure,\n origin_location_id,\n destination_location_id,\n ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY scheduled_departure) as rn\n FROM transportation.trips\n)\nSELECT\n t1.trip_id AS first_trip_id,\n t2.trip_id AS second_trip_id,\n t1.vehicle_id,\n t1.scheduled_departure AS first_scheduled_departure,\n t2.scheduled_departure AS second_scheduled_departure,\n t1.destination_location_id AS first_destination_location_id,\n t2.origin_location_id AS second_origin_location_id\nFROM RankedTrips AS t1\nJOIN RankedTrips AS t2\n ON t1.vehicle_id = t2.vehicle_id AND t1.rn + 1 = t2.rn;"}, {"role": "user", "content": "From these consecutive pairs, only show those where the destination of the first trip matches the origin of the second trip."}, {"role": "assistant", "content": "WITH RankedTrips AS (\n SELECT\n trip_id,\n vehicle_id,\n scheduled_departure,\n origin_location_id,\n destination_location_id,\n ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY scheduled_departure) as rn\n FROM transportation.trips\n)\nSELECT\n t1.trip_id AS first_trip_id,\n t2.trip_id AS second_trip_id,\n t1.vehicle_id,\n t1.scheduled_departure AS first_scheduled_departure,\n t2.scheduled_departure AS second_scheduled_departure,\n t1.destination_location_id AS first_destination_location_id,\n t2.origin_location_id AS second_origin_location_id\nFROM RankedTrips AS t1\nJOIN RankedTrips AS t2\n ON t1.vehicle_id = t2.vehicle_id AND t1.rn + 1 = t2.rn\nWHERE\n t1.destination_location_id = t2.origin_location_id;"}, {"role": "user", "content": "Also, only include pairs where the time difference between the scheduled departures is less than 24 hours."}, {"role": "assistant", "content": "WITH RankedTrips AS (\n SELECT\n trip_id,\n vehicle_id,\n scheduled_departure,\n origin_location_id,\n destination_location_id,\n ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY scheduled_departure) as rn\n FROM transportation.trips\n)\nSELECT\n t1.trip_id AS first_trip_id,\n t2.trip_id AS second_trip_id,\n t1.vehicle_id,\n t1.scheduled_departure AS first_scheduled_departure,\n t2.scheduled_departure AS second_scheduled_departure,\n t1.destination_location_id AS first_destination_location_id,\n t2.origin_location_id AS second_origin_location_id\nFROM RankedTrips AS t1\nJOIN RankedTrips AS t2\n ON t1.vehicle_id = t2.vehicle_id AND t1.rn + 1 = t2.rn\nWHERE\n t1.destination_location_id = t2.origin_location_id\n AND t2.scheduled_departure < t1.scheduled_departure + INTERVAL '24 hour';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n", "conversations": [{"role": "user", "content": "List the latitude and longitude coordinates for all service locations located in a city named 'Seattle'."}, {"role": "assistant", "content": "SELECT latitude , longitude FROM government_services.service_locations WHERE city = 'Seattle'"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE token_dexpool_info ( pair_address text, token_name text, token_symbol text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_6h numeric, price_change_percentage_24h numeric, makers_24h numeric, volume_24h numeric, liquidity numeric, market_cap numeric, trend_rank numeric )\nCREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_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 average ROI for smart money addresses on the Binance chain?"}, {"role": "assistant", "content": "SELECT AVG(roi) FROM smart_money_profit WHERE chain = 'Binance';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\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": "What is the average profit of smart money addresses whose profit is above $1,000, grouped by chain?"}, {"role": "assistant", "content": "SELECT chain, AVG(profit) AS avg_profit\nFROM smart_money_profit\nWHERE profit > 1000\nGROUP BY chain;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List all group chat conversations and the number of messages in each group chat."}, {"role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.messages m\n ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = true\nGROUP BY c.conversation_id, c.group_name;"}, {"role": "user", "content": "Actually, only include group chats with more than 10 messages and order by message_count descending."}, {"role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.messages m\n ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = true\nGROUP BY c.conversation_id, c.group_name\nHAVING COUNT(m.message_id) > 10\nORDER BY message_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "How many projects raised funds in 2023?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS project_count\nFROM project_fundraising_record\nWHERE investment_date LIKE '2023-%';"}, {"role": "user", "content": "Also provide the average investment_value for these projects."}, {"role": "assistant", "content": "SELECT COUNT(*) AS project_count, AVG(investment_value) AS avg_investment\nFROM project_fundraising_record\nWHERE investment_date LIKE '2023-%';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n", "conversations": [{"role": "user", "content": "For each property, show the number of guests who have checked in since the start of this year."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(DISTINCT res.guest_id) AS guest_count\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'CheckedIn' AND res.actual_check_in_ts >= DATE_TRUNC('year', CURRENT_DATE)\nGROUP BY p.property_name;"}, {"role": "user", "content": "Can you also include the total number of unique reservations per property in that time frame?"}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(DISTINCT res.guest_id) AS guest_count, COUNT(res.reservation_id) AS reservation_count\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'CheckedIn' AND res.actual_check_in_ts >= DATE_TRUNC('year', CURRENT_DATE)\nGROUP BY p.property_name;"}, {"role": "user", "content": "Please also show the average length of stay (in days) for these reservations per property."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(DISTINCT res.guest_id) AS guest_count,\n COUNT(res.reservation_id) AS reservation_count,\n AVG(res.check_out_date - res.check_in_date) AS avg_length_of_stay_days\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'CheckedIn' AND res.actual_check_in_ts >= DATE_TRUNC('year', CURRENT_DATE)\nGROUP BY p.property_name;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nUse Hashes. Key pattern: '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\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 )\n", "conversations": [{"role": "user", "content": "What is the average estimated_duration_minutes for each route type?"}, {"role": "assistant", "content": "SELECT type, AVG(estimated_duration_minutes) AS average_duration FROM transportation.routes GROUP BY type;"}, {"role": "user", "content": "Now filter to include only route types with average duration greater than 60 minutes and order by average duration descending."}, {"role": "assistant", "content": "SELECT type, AVG(estimated_duration_minutes) AS average_duration FROM transportation.routes GROUP BY type HAVING AVG(estimated_duration_minutes) > 60 ORDER BY average_duration DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve the invoice_number, issue_date, total_amount, client_id, and case_name for all invoices with status 'Sent' issued between '2024-07-01' and '2024-07-31'. Order the results by issue_date descending."}, {"role": "assistant", "content": "SELECT i.invoice_number, i.issue_date, i.total_amount, i.client_id, c.case_name\nFROM legal_services.invoices i\nJOIN legal_services.cases c ON i.case_id = c.case_id\nWHERE i.status = 'Sent'\n AND i.issue_date BETWEEN '2024-07-01' AND '2024-07-31'\nORDER BY i.issue_date DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\n", "conversations": [{"role": "user", "content": "Which agents have sold policies with a coverage limit over 1,000,000, and what are the policy numbers and their respective coverage limits?"}, {"role": "assistant", "content": "SELECT agent_id, policy_number, coverage_limit FROM insurance.policies WHERE coverage_limit > 1000000;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\n", "conversations": [{"role": "user", "content": "List all smoking rooms, showing the property name, room number, and room type name."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.room_number, T3.type_name FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.rooms AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.room_types AS T3 ON T2.room_type_id = T3.room_type_id WHERE T2.is_smoking = true"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all users who have participated in group conversations created in April 2024, showing their username, conversation ID, and the group name."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.conversation_id, c.group_name\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true\n AND c.created_at >= '2024-04-01' AND c.created_at < '2024-05-01';"}, {"role": "user", "content": "Instead of all users, show only those who joined the group conversation after it was created."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.conversation_id, c.group_name\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true\n AND c.created_at >= '2024-04-01' AND c.created_at < '2024-05-01'\n AND cp.joined_at > c.created_at;"}, {"role": "user", "content": "I only care about group conversations where the group name contains the word 'Study'."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.conversation_id, c.group_name\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true\n AND c.created_at >= '2024-04-01' AND c.created_at < '2024-05-01'\n AND cp.joined_at > c.created_at\n AND c.group_name ILIKE '%Study%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "I want to get the list of users and their total number of public posts made in the last month, including user_id and post_count."}, {"role": "assistant", "content": "SELECT user_id, COUNT(*) AS post_count\nFROM social_media.posts\nWHERE visibility = 'public'\n AND created_at >= CURRENT_DATE - INTERVAL '1 month'\nGROUP BY user_id;"}, {"role": "user", "content": "Actually, include only users whose email_notifications_enabled is true."}, {"role": "assistant", "content": "SELECT p.user_id, COUNT(*) AS post_count\nFROM social_media.posts p\nJOIN social_media.user_settings u\n ON p.user_id = u.user_id\nWHERE p.visibility = 'public'\n AND p.created_at >= CURRENT_DATE - INTERVAL '1 month'\n AND u.email_notifications_enabled = true\nGROUP BY p.user_id;"}, {"role": "user", "content": "Also only consider posts that have media_type 'image'."}, {"role": "assistant", "content": "SELECT p.user_id, COUNT(*) AS post_count\nFROM social_media.posts p\nJOIN social_media.user_settings u\n ON p.user_id = u.user_id\nWHERE p.visibility = 'public'\n AND p.created_at >= CURRENT_DATE - INTERVAL '1 month'\n AND u.email_notifications_enabled = true\n AND p.media_type = 'image'\nGROUP BY p.user_id;"}, {"role": "user", "content": "Order the results by post_count descending and limit to the top 10."}, {"role": "assistant", "content": "SELECT p.user_id, COUNT(*) AS post_count\nFROM social_media.posts p\nJOIN social_media.user_settings u\n ON p.user_id = u.user_id\nWHERE p.visibility = 'public'\n AND p.created_at >= CURRENT_DATE - INTERVAL '1 month'\n AND u.email_notifications_enabled = true\n AND p.media_type = 'image'\nGROUP BY p.user_id\nORDER BY post_count DESC\nLIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.messages ( message_id.text, conversation_id.text, sender_user_id.text, content.text, media_url.text, media_type.text, sent_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id text, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all messages that haven’t triggered any notification; show message_id, sender_user_id, and sent_at."}, {"role": "assistant", "content": "SELECT m.message_id, m.sender_user_id, m.sent_at\nFROM social_media.messages AS m\nLEFT JOIN social_media.notifications AS n\n ON n.target_entity_type = 'message'\n AND n.target_entity_id = m.message_id\nWHERE n.notification_id IS NULL;"}, {"role": "user", "content": "Actually, only include those sent before '2024-06-01'."}, {"role": "assistant", "content": "SELECT m.message_id, m.sender_user_id, m.sent_at\nFROM social_media.messages AS m\nLEFT JOIN social_media.notifications AS n\n ON n.target_entity_type = 'message'\n AND n.target_entity_id = m.message_id\nWHERE n.notification_id IS NULL\n AND m.sent_at < '2024-06-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "Show the post ID and hashtags for all posts containing the word 'conference' in their content."}, {"role": "assistant", "content": "SELECT p.post_id, h.hashtag_id, h.tag_name\nFROM social_media.posts p\nJOIN social_media.post_hashtags ph ON p.post_id = ph.post_id\nJOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id\nWHERE p.content ILIKE '%conference%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Count how many follow relationships were created in June 2024."}, {"role": "assistant", "content": "SELECT COUNT(follow_id) FROM social_media.follows WHERE created_at >= '2024-06-01' AND created_at < '2024-07-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "I want to know the usernames of users who have followed more than three different people, along with the date they created their accounts."}, {"role": "assistant", "content": "SELECT u.username, u.created_at, COUNT(DISTINCT f.following_user_id) AS following_count\nFROM social_media.users u\nJOIN social_media.follows f ON u.user_id = f.follower_user_id\nGROUP BY u.user_id, u.username, u.created_at\nHAVING COUNT(DISTINCT f.following_user_id) > 3;"}, {"role": "user", "content": "Also include the usernames of up to two users they are following for each user in the result."}, {"role": "assistant", "content": "SELECT u.username AS follower_username, u.created_at, uf.username AS following_username\nFROM social_media.users u\nJOIN social_media.follows f ON u.user_id = f.follower_user_id\nJOIN social_media.users uf ON f.following_user_id = uf.user_id\nWHERE u.user_id IN (\n SELECT f1.follower_user_id\n FROM social_media.follows f1\n GROUP BY f1.follower_user_id\n HAVING COUNT(DISTINCT f1.following_user_id) > 3\n)\nORDER BY u.username, f.created_at\nLIMIT 2;"}, {"role": "user", "content": "Can you instead provide all usernames they follow, not just two, and include the follow creation date as well?"}, {"role": "assistant", "content": "SELECT u.username AS follower_username, u.created_at AS follower_created_at, uf.username AS following_username, f.created_at AS follow_created_at\nFROM social_media.users u\nJOIN social_media.follows f ON u.user_id = f.follower_user_id\nJOIN social_media.users uf ON f.following_user_id = uf.user_id\nWHERE u.user_id IN (\n SELECT f1.follower_user_id\n FROM social_media.follows f1\n GROUP BY f1.follower_user_id\n HAVING COUNT(DISTINCT f1.following_user_id) > 3\n)\nORDER BY u.username, f.created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text, tag_name text, created_at timestamp )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List all comments on a given post along with the commenter’s username and the comment time."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content, u.username, c.created_at\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id = '';"}, {"role": "user", "content": "Please also indicate if the comment is a reply by showing the parent_comment_id as well."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content, u.username, c.created_at, c.parent_comment_id\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id = '';"}, {"role": "user", "content": "Filter to only show the top-level comments (those without a parent_comment_id)."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content, u.username, c.created_at, c.parent_comment_id\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id = ''\n AND c.parent_comment_id IS NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\n", "conversations": [{"role": "user", "content": "How many group conversations are there?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.conversations WHERE is_group_chat = TRUE;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\nCREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each block, get the count of failed transactions and the total gas used by these failed transactions. Show block_number, failed_tx_count, and total_failed_gas."}, {"role": "assistant", "content": "SELECT block_number,\n COUNT(*) FILTER (WHERE status = 'failed') AS failed_tx_count,\n SUM(gas_used) FILTER (WHERE status = 'failed') AS total_failed_gas\nFROM web3.transactions\nGROUP BY block_number;"}, {"role": "user", "content": "Actually, I need only blocks with failed_tx_count greater than 10."}, {"role": "assistant", "content": "SELECT block_number,\n COUNT(*) FILTER (WHERE status = 'failed') AS failed_tx_count,\n SUM(gas_used) FILTER (WHERE status = 'failed') AS total_failed_gas\nFROM web3.transactions\nGROUP BY block_number\nHAVING COUNT(*) FILTER (WHERE status = 'failed') > 10;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.maintenance_records ( record_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, asset_type character varying(32) NOT NULL, maintenance_type character varying(128) NOT NULL, staff_id character varying(64), start_datetime timestamp NOT NULL, end_datetime timestamp, description text NOT NULL, cost numeric(12, 2), status character varying(32) NOT NULL DEFAULT 'Completed', PRIMARY KEY (record_id), FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "What is the reason behind the cost variation for maintenance of asset_id 'ASSET456' over the past year?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information on the reasons behind cost variations for maintenance. The data in the maintenance_records table includes only the cost amount and other basic details of each maintenance record, but it does not contain explanations or factors influencing cost changes."}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\n", "conversations": [{"role": "user", "content": "Find all guests who live in the same city and list each guest's name along with the name of another guest in that city."}, {"role": "assistant", "content": "SELECT g1.first_name || ' ' || g1.last_name AS guest_name,\n g2.first_name || ' ' || g2.last_name AS other_guest_name,\n g1.city\nFROM guests g1\nJOIN guests g2\n ON g1.city = g2.city\n AND g1.guest_id <> g2.guest_id;"}, {"role": "user", "content": "Now restrict to only cities with more than two guests and order by city ascending."}, {"role": "assistant", "content": "SELECT pairs.city,\n pairs.guest_name,\n pairs.other_guest_name\nFROM (\n SELECT g1.first_name || ' ' || g1.last_name AS guest_name,\n g2.first_name || ' ' || g2.last_name AS other_guest_name,\n g1.city\n FROM guests g1\n JOIN guests g2\n ON g1.city = g2.city\n AND g1.guest_id <> g2.guest_id\n) AS pairs\nJOIN (\n SELECT city\n FROM guests\n GROUP BY city\n HAVING COUNT(*) > 2\n) AS multi\n ON pairs.city = multi.city\nORDER BY pairs.city ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\n", "conversations": [{"role": "user", "content": "I want to see pairs of fundraising rounds for projects that have at least two rounds. Please list project_name, earlier_round, earlier_investment, later_round, and later_investment."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date;"}, {"role": "user", "content": "Only include pairs where later_investment is greater than earlier_investment."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date\nWHERE later.investment_value > earlier.investment_value;"}, {"role": "user", "content": "Also calculate the valuation change between the two rounds as valuation_diff."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment,\n (later.valuation - earlier.valuation) AS valuation_diff\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date\nWHERE later.investment_value > earlier.investment_value;"}, {"role": "user", "content": "Order by the investment increase descending and limit to top 5."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment,\n (later.valuation - earlier.valuation) AS valuation_diff\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date\nWHERE later.investment_value > earlier.investment_value\nORDER BY (later.investment_value - earlier.investment_value) DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\n", "conversations": [{"role": "user", "content": "Show me all assets whose symbol starts with 'BTC' or 'ETH', along with their full names and types."}, {"role": "assistant", "content": "SELECT asset_id, name, symbol, type FROM trading_platform.assets WHERE symbol LIKE 'BTC%' OR symbol LIKE 'ETH%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\n", "conversations": [{"role": "user", "content": "List all pairs of vehicles with the same make and model but different manufacture years. Include each vehicle's ID, make, model, and both years."}, {"role": "assistant", "content": "SELECT v1.vehicle_id AS vehicle1_id, v2.vehicle_id AS vehicle2_id, v1.make, v1.model, v1.year AS year1, v2.year AS year2\nFROM transportation.vehicles v1\nJOIN transportation.vehicles v2\n ON v1.make = v2.make\n AND v1.model = v2.model\n AND v1.year <> v2.year\n AND v1.vehicle_id < v2.vehicle_id\nORDER BY v1.make, v1.model, v1.year;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\n", "conversations": [{"role": "user", "content": "List all trades for asset 'BTC' where the trade quantity is greater than 5."}, {"role": "assistant", "content": "SELECT trade_id, order_id, buyer_id, seller_id, quantity, price, traded_at FROM trading_platform.trades WHERE asset_id = 'BTC' AND quantity > 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Provide a count of contracts for each unique combination of network ID and status."}, {"role": "assistant", "content": "SELECT network_id, status, COUNT(*) FROM web3.contracts GROUP BY network_id, status;"}, {"role": "user", "content": "Now, only show the network IDs from the previous result that have contracts in more than one distinct status."}, {"role": "assistant", "content": "SELECT network_id FROM web3.contracts GROUP BY network_id HAVING COUNT(DISTINCT status) > 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\n", "conversations": [{"role": "user", "content": "Provide a count of transactions grouped by their status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM web3.transactions GROUP BY status;"}, {"role": "user", "content": "Now, only show the statuses that have more than 50 transactions."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM web3.transactions GROUP BY status HAVING COUNT(*) > 50;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\n", "conversations": [{"role": "user", "content": "For each event, display its event_id, the event_id of the previous event in the same transaction (if any), and the log_index of both events."}, {"role": "assistant", "content": "SELECT curr.event_id AS current_event_id,\n prev.event_id AS previous_event_id,\n curr.log_index AS current_log_index,\n prev.log_index AS previous_log_index,\n curr.transaction_id\nFROM web3.events curr\nLEFT JOIN web3.events prev\n ON curr.transaction_id = prev.transaction_id\n AND curr.log_index = prev.log_index + 1;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars ( car_id character varying(64) NOT NULL, train_id character varying(64) NOT NULL, car_number character varying(10) NOT NULL, car_type character varying(64) NOT NULL, class character varying(32), capacity integer, features text, PRIMARY KEY (car_id), FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id) )\n", "conversations": [{"role": "user", "content": "What is the maintenance schedule for the train car with car_id 'CAR456'?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information about the maintenance schedule for train cars as it is not included in the data available in the train_cars table."}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "List the username, registration date, and the creation date of the first wallet created by each user who owns at least one wallet."}, {"role": "assistant", "content": "SELECT u.username, u.created_at AS registration_date, MIN(w.created_at) AS first_wallet_creation_date FROM web3.users AS u JOIN web3.wallets AS w ON u.user_id = w.user_id GROUP BY u.user_id, u.username, u.created_at;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars (\n car_id character varying(64) NOT NULL, -- Unique identifier for the train car\n train_id character varying(64) NOT NULL, -- Foreign key referencing trains\n car_number character varying(10) NOT NULL, -- Identifier of the car within the train set\n car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage\n class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars)\n capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars)\n features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom')\n PRIMARY KEY (car_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id)\n)\n", "conversations": [{"role": "user", "content": "What is the current location of a specific train car with car_id 'TC123'?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide the current location of a specific train car as this information is not stored in the database table. The table only contains static details about train cars such as car type, capacity, and features. For real-time location data, please refer to the train tracking system or contact the relevant department."}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "Show all fuel logs for vehicle_id 'VH123', including the timestamp, fuel type, quantity, and the location_id. Sort the list by timestamp descending."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "Can you also include the odometer reading and total cost for each fuel log in the result?"}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "I only want to see records where the total_cost is above 100."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\n AND total_cost > 100\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "Actually, please limit the results to just the 5 most recent logs."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\n AND total_cost > 100\nORDER BY log_timestamp DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies (\n policy_id character varying(64) NOT NULL, -- unique identifier for the policy\n customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)\n product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)\n agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)\n policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number\n start_date date NOT NULL, -- date the policy coverage begins\n end_date date NOT NULL, -- date the policy coverage ends\n premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term\n coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered\n deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in\n status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending\n issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued\n cancellation_date date,\n cancellation_reason text,\n PRIMARY KEY (policy_id)\n)\n", "conversations": [{"role": "user", "content": "Show me a list of all policy numbers that have a deductible exactly equal to 0."}, {"role": "assistant", "content": "SELECT policy_number\nFROM insurance.policies\nWHERE deductible = 0;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, token_symbol character varying(100), token_amount numeric(38,2), usd_value numeric(38,2), avg_price numeric(38,6), type int, address_amount integer, narrative character varying(100), chain character varying(100) )\n", "conversations": [{"role": "user", "content": "Show me the top 5 projects by total investment value, along with their latest fundraising round name and valuation."}, {"role": "assistant", "content": "SELECT project_name, rounds_name, valuation, SUM(investment_value) AS total_investment_value FROM project_fundraising_record GROUP BY project_name, rounds_name, valuation ORDER BY total_investment_value DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include the investment date for these projects?"}, {"role": "assistant", "content": "SELECT project_name, rounds_name, valuation, investment_date, SUM(investment_value) AS total_investment_value FROM project_fundraising_record GROUP BY project_name, rounds_name, valuation, investment_date ORDER BY total_investment_value DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.routes (\n route_id character varying(64) NOT NULL, -- unique identifier for the route\n route_number character varying(32) NOT NULL UNIQUE, -- public-facing route number/name\n description text, -- description of the route\n origin_location_id character varying(64) NOT NULL, -- identifier of the starting location\n destination_location_id character varying(64) NOT NULL, -- identifier of the ending location\n distance_km numeric(10, 2), -- estimated distance in kilometers\n estimated_duration_minutes integer, -- estimated travel time in minutes\n type character varying(32) NOT NULL, -- e.g., City Bus, Intercity Train, Cargo Delivery\n PRIMARY KEY (route_id)\n)\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America/New_York)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "List all depots (location type 'Depot') and the number of vehicles assigned to each. Include the depot name and city."}, {"role": "assistant", "content": "SELECT T1.name , T1.city , COUNT(T2.vehicle_id) FROM transportation.locations AS T1 LEFT JOIN transportation.vehicles AS T2 ON T1.location_id = T2.depot_id WHERE T1.type = 'Depot' GROUP BY T1.location_id , T1.name , T1.city"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Count the number of contracts for each network_id."}, {"role": "assistant", "content": "SELECT network_id, COUNT(*) FROM web3.contracts GROUP BY network_id;"}, {"role": "user", "content": "Now, only show networks with more than 100 contracts."}, {"role": "assistant", "content": "SELECT network_id, COUNT(*) FROM web3.contracts GROUP BY network_id HAVING COUNT(*) > 100;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.policy_beneficiaries (\n beneficiary_id character varying(64) NOT NULL, -- unique identifier for the beneficiary entry\n policy_id character varying(64) NOT NULL, -- identifier of the life/relevant policy (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the beneficiary (could be FK to customers or store info directly)\n first_name character varying(100) NOT NULL, -- beneficiary first name (if not linking to customers table)\n last_name character varying(100) NOT NULL, -- beneficiary last name\n relationship character varying(50) NOT NULL, -- relationship to the policyholder (e.g., Spouse, Child, Parent)\n percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), -- percentage of payout\n contact_info text, -- contact details for the beneficiary\n added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (beneficiary_id),\n UNIQUE (policy_id, customer_id) -- Ensure a person is listed only once per policy\n)\n", "conversations": [{"role": "user", "content": "For each claim, count the number of beneficiaries associated with its policy. Show claim_id and beneficiary_count, only for claims with more than 2 beneficiaries."}, {"role": "assistant", "content": "SELECT c.claim_id, COUNT(pb.beneficiary_id) AS beneficiary_count\nFROM insurance.claims c\nJOIN insurance.policy_beneficiaries pb ON c.policy_id = pb.policy_id\nGROUP BY c.claim_id\nHAVING COUNT(pb.beneficiary_id) > 2;"}, {"role": "user", "content": "Now restrict the result to claims reported in 2023."}, {"role": "assistant", "content": "SELECT c.claim_id, COUNT(pb.beneficiary_id) AS beneficiary_count\nFROM insurance.claims c\nJOIN insurance.policy_beneficiaries pb ON c.policy_id = pb.policy_id\nWHERE c.reported_date >= '2023-01-01' AND c.reported_date < '2024-01-01'\nGROUP BY c.claim_id\nHAVING COUNT(pb.beneficiary_id) > 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.routes (\n route_id character varying(64) NOT NULL, -- unique identifier for the route\n route_number character varying(32) NOT NULL UNIQUE, -- public-facing route number/name\n description text, -- description of the route\n origin_location_id character varying(64) NOT NULL, -- identifier of the starting location\n destination_location_id character varying(64) NOT NULL, -- identifier of the ending location\n distance_km numeric(10, 2), -- estimated distance in kilometers\n estimated_duration_minutes integer, -- estimated travel time in minutes\n type character varying(32) NOT NULL, -- e.g., City Bus, Intercity Train, Cargo Delivery\n PRIMARY KEY (route_id)\n)\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\nCREATE TABLE transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all drivers and the vehicles they are assigned for trips that have status 'Delayed'. Include driver first_name, driver last_name, vehicle license_plate, trip_id, and actual_departure."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, v.license_plate, t.trip_id, t.actual_departure\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Delayed';"}, {"role": "user", "content": "Now limit to delays where the actual_departure is more than 15 minutes after scheduled_departure and order by the delay duration in descending order."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, v.license_plate, t.trip_id, t.actual_departure,\n EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))/60 AS delay_minutes\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Delayed'\n AND (t.actual_departure - t.scheduled_departure) > INTERVAL '15 minutes'\nORDER BY delay_minutes DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.routes (\n route_id character varying(64) NOT NULL, -- unique identifier for the route\n route_number character varying(32) NOT NULL UNIQUE, -- public-facing route number/name\n description text, -- description of the route\n origin_location_id character varying(64) NOT NULL, -- identifier of the starting location\n destination_location_id character varying(64) NOT NULL, -- identifier of the ending location\n distance_km numeric(10, 2), -- estimated distance in kilometers\n estimated_duration_minutes integer, -- estimated travel time in minutes\n type character varying(32) NOT NULL, -- e.g., City Bus, Intercity Train, Cargo Delivery\n PRIMARY KEY (route_id)\n)\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "Show the most recent maintenance service for each vehicle, including the vehicle's make and model."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n);"}, {"role": "user", "content": "Can you also add the mechanic's name and the maintenance cost in the result?"}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading, m.mechanic_name, m.cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n);"}, {"role": "user", "content": "Actually, only include records where the maintenance cost is above 200."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading, m.mechanic_name, m.cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n)\nAND m.cost > 200;"}, {"role": "user", "content": "Please order the result by maintenance cost in descending order."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading, m.mechanic_name, m.cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n)\nAND m.cost > 200\nORDER BY m.cost DESC;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.stations ( station_id character varying(64) NOT NULL, station_name character varying(128) NOT NULL, city character varying(100) NOT NULL, state_province character varying(100), country_code character varying(3) NOT NULL, address text, timezone character varying(64) NOT NULL, number_of_platforms integer NOT NULL DEFAULT 0, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (station_id) )\n", "conversations": [{"role": "user", "content": "What are the ticket prices for trains departing from the station with ID 'ST456'?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information on ticket prices as this data is not included in the station management database. For ticket pricing, please refer to the ticketing system or contact customer service."}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all vehicles that are due for their next service before the end of this month, along with their last service type and date."}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, service_date FROM transportation.maintenance_logs WHERE next_service_due_date <= DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month' - INTERVAL '1 day';"}, {"role": "user", "content": "Can you include the mechanic who performed the last service and order by how soon the next service is due?"}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, service_date, mechanic_name, next_service_due_date FROM transportation.maintenance_logs WHERE next_service_due_date <= DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month' - INTERVAL '1 day' ORDER BY next_service_due_date ASC;"}, {"role": "user", "content": "There seems to be a typo in your SQL - it should be 'INTERVAL' not 'INTERVAL'. Also, can you include the cost of the last service?"}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, service_date, mechanic_name, next_service_due_date, cost FROM transportation.maintenance_logs WHERE next_service_due_date <= DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month' - INTERVAL '1 day' ORDER BY next_service_due_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\n", "conversations": [{"role": "user", "content": "List all token transfers between two distinct addresses, showing transfer_id, from_address, to_address, value, and transaction_id."}, {"role": "assistant", "content": "SELECT transfer_id, from_address, to_address, value, transaction_id\nFROM web3.token_transfers\nWHERE from_address <> to_address;"}, {"role": "user", "content": "Actually, I only want to see transfers where the value transferred is greater than 1000 tokens."}, {"role": "assistant", "content": "SELECT transfer_id, from_address, to_address, value, transaction_id\nFROM web3.token_transfers\nWHERE from_address <> to_address AND value > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n", "conversations": [{"role": "user", "content": "Provide a list of passengers including their passenger_id, first_name, last_name, phone_number, and the total number of bookings they have made. Sort the result by booking count in descending order."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n p.phone_number,\n COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name,\n p.phone_number\nORDER BY booking_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.token_transfers ( transfer_id character varying(64) NOT NULL, token_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128) NOT NULL, value numeric(38,14) NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (transfer_id) )\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "Show all token transfers including the token symbol and the address of the contract that created each token. List the transfer id, token id, value, transaction id, the contract address, and the token symbol."}, {"role": "assistant", "content": "SELECT tt.transfer_id, tt.token_id, tt.value, tt.transaction_id, t.contract_id AS contract_address, t.token_symbol\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address text NOT NULL, city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status character varying(32) NOT NULL, risk_profile character varying(50), PRIMARY KEY (customer_id) )\nCREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )\nCREATE TABLE financial_services.securities ( security_id character varying(64) NOT NULL, ticker_symbol character varying(20) NOT NULL UNIQUE, isin_code character varying(12) UNIQUE, cusip_code character varying(9) UNIQUE, security_name text NOT NULL, security_type character varying(50) NOT NULL, exchange character varying(50), currency character varying(3) NOT NULL, issuer_name character varying(255), sector character varying(100), last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (security_id) )\nCREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\nCREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n", "conversations": [{"role": "user", "content": "Show the average close price and total volume for market data, grouped by source."}, {"role": "assistant", "content": "SELECT source, AVG(close_price), SUM(volume) FROM financial_services.market_data GROUP BY source;"}, {"role": "user", "content": "Only include data points with volume greater than 100000 and exclude sources where the total volume is less than 10000000."}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "I want to see pairs of medications that share the same manufacturer. Show each medication's name and its peer's medication_name along with the manufacturer."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer;"}, {"role": "user", "content": "Exclude any rows where a medication is paired with itself."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer AND t1.medication_id <> t2.medication_id;"}, {"role": "user", "content": "Now only include manufacturers 'Pfizer' or 'Moderna'."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer AND t1.medication_id <> t2.medication_id WHERE t1.manufacturer IN ('Pfizer','Moderna');"}, {"role": "user", "content": "I’m seeing duplicate pairs for reversed order. Remove reversed duplicates."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer AND t1.medication_id < t2.medication_id WHERE t1.manufacturer IN ('Pfizer','Moderna');"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each vehicle that appears in both the maintenance logs and fuel logs tables, calculate the total maintenance cost and the total fuel cost. Display the vehicle ID and these two total costs."}, {"role": "assistant", "content": "SELECT T1.vehicle_id , SUM(T1.cost) AS total_maintenance_cost , SUM(T2.total_cost) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id"}, {"role": "user", "content": "Now, only include vehicles where the total maintenance cost exceeds 5000."}, {"role": "assistant", "content": "SELECT T1.vehicle_id , SUM(T1.cost) AS total_maintenance_cost , SUM(T2.total_cost) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id HAVING SUM(T1.cost) > 5000"}, {"role": "user", "content": "Also, only consider fuel log entries from the year 2023 for the fuel cost calculation."}, {"role": "assistant", "content": "SELECT T1.vehicle_id , SUM(T1.cost) AS total_maintenance_cost , SUM(CASE WHEN STRFTIME('%Y', T2.log_timestamp) = '2023' THEN T2.total_cost ELSE 0 END) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id HAVING SUM(T1.cost) > 5000"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n", "conversations": [{"role": "user", "content": "Show the game title and the count of hidden achievements for each game."}, {"role": "assistant", "content": "SELECT T1.title , COUNT(T2.achievement_id) FROM games AS T1 JOIN achievements AS T2 ON T1.game_id = T2.game_id WHERE T2.hidden = TRUE GROUP BY T1.title"}, {"role": "user", "content": "Filter the results to only include games that have at least one hidden achievement."}, {"role": "assistant", "content": "SELECT T1.title , COUNT(T2.achievement_id) FROM games AS T1 JOIN achievements AS T2 ON T1.game_id = T2.game_id WHERE T2.hidden = TRUE GROUP BY T1.title HAVING COUNT(T2.achievement_id) >= 1"}, {"role": "user", "content": "Order the results by the count of hidden achievements descending."}, {"role": "assistant", "content": "SELECT T1.title , COUNT(T2.achievement_id) FROM games AS T1 JOIN achievements AS T2 ON T1.game_id = T2.game_id WHERE T2.hidden = TRUE GROUP BY T1.title HAVING COUNT(T2.achievement_id) >= 1 ORDER BY COUNT(T2.achievement_id) DESC"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n", "conversations": [{"role": "user", "content": "List the names of all open cases, the name of the client for each case, and the name of the lead lawyer, but only for cases where the lead lawyer specializes in 'Family Law'."}, {"role": "assistant", "content": "SELECT T1.case_name , T2.first_name , T2.last_name , T3.first_name , T3.last_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T3 ON T1.lead_lawyer_id = T3.lawyer_id WHERE T1.status = 'Open' AND T3.specialization = 'Family Law'"}, {"role": "user", "content": "Actually, could you change the specialization filter to 'Criminal Law' and include the case number? Also, please sort the results by the client's last name."}, {"role": "assistant", "content": "SELECT T1.case_number , T1.case_name , T2.first_name , T2.last_name , T3.first_name , T3.last_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T3 ON T1.lead_lawyer_id = T3.lawyer_id WHERE T1.status = 'Open' AND T3.specialization = 'Criminal Law' ORDER BY T2.last_name"}, {"role": "user", "content": "Okay, now just show the cases that were opened after '2023-07-01'."}, {"role": "assistant", "content": "SELECT T1.case_number , T1.case_name , T2.first_name , T2.last_name , T3.first_name , T3.last_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T3 ON T1.lead_lawyer_id = T3.lawyer_id WHERE T1.status = 'Open' AND T3.specialization = 'Criminal Law' AND T1.date_opened > '2023-07-01' ORDER BY T2.last_name"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n", "conversations": [{"role": "user", "content": "Which two tokens on each chain have the greatest difference in their 24h price change percentage? Show token_symbol A, token_symbol B, chain, and the absolute difference."}, {"role": "assistant", "content": "SELECT DISTINCT ON (t1.chain)\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h\nFROM token_dexpool_info t1\nJOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\nORDER BY t1.chain, diff_24h DESC;"}, {"role": "user", "content": "Actually, I want only the chains where this top difference is at least 15% and show the top 2 pairs per chain."}, {"role": "assistant", "content": "SELECT symbol_a, symbol_b, chain, diff_24h\nFROM (\n SELECT\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h,\n ROW_NUMBER() OVER(\n PARTITION BY t1.chain\n ORDER BY ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) DESC\n ) AS rn\n FROM token_dexpool_info t1\n JOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\n WHERE ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) >= 15\n) sub\nWHERE rn <= 2\nORDER BY chain, diff_24h DESC;"}, {"role": "user", "content": "Also sort the overall result by diff_24h descending and limit to the top 5 records."}, {"role": "assistant", "content": "SELECT *\nFROM (\n SELECT symbol_a, symbol_b, chain, diff_24h\n FROM (\n SELECT\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h,\n ROW_NUMBER() OVER(\n PARTITION BY t1.chain\n ORDER BY ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) DESC\n ) AS rn\n FROM token_dexpool_info t1\n JOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\n WHERE ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) >= 15\n ) sub1\n WHERE rn <= 2\n) sub2\nORDER BY diff_24h DESC\nLIMIT 5;"}, {"role": "user", "content": "Could you include the current price of both tokens in the output as well?"}, {"role": "assistant", "content": "SELECT symbol_a, symbol_b, chain, price_a, price_b, diff_24h\nFROM (\n SELECT\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n t1.price AS price_a,\n t2.price AS price_b,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h,\n ROW_NUMBER() OVER(\n PARTITION BY t1.chain\n ORDER BY ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) DESC\n ) AS rn\n FROM token_dexpool_info t1\n JOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\n WHERE ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) >= 15\n) sub\nWHERE rn <= 2\nORDER BY diff_24h DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\n", "conversations": [{"role": "user", "content": "Can you show me all pairs of trips that use the same vehicle but have different drivers? Please include both trip IDs, vehicle_id, and the driver_id for each trip."}, {"role": "assistant", "content": "SELECT t1.trip_id AS trip_id_1, t2.trip_id AS trip_id_2, t1.vehicle_id, t1.driver_id AS driver_id_1, t2.driver_id AS driver_id_2\nFROM transportation.trips t1\nJOIN transportation.trips t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\n AND t1.driver_id <> t2.driver_id;"}, {"role": "user", "content": "Actually, I also want to see only those pairs where both trips have a status of 'Completed'."}, {"role": "assistant", "content": "SELECT t1.trip_id AS trip_id_1, t2.trip_id AS trip_id_2, t1.vehicle_id, t1.driver_id AS driver_id_1, t2.driver_id AS driver_id_2\nFROM transportation.trips t1\nJOIN transportation.trips t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\n AND t1.driver_id <> t2.driver_id\nWHERE t1.status = 'Completed' AND t2.status = 'Completed';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.nodes (\n node_id character varying(64) NOT NULL, -- unique identifier for the node\n ip_address character varying(15) NOT NULL, -- IP address of the node\n port integer NOT NULL, -- port number of the node\n last_seen timestamp NOT NULL, -- last time the node was active\n PRIMARY KEY (node_id)\n)\nCREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE blockchain.smart_contracts ( contract_id character varying(64) NOT NULL, creator_address character varying(128) NOT NULL, code text NOT NULL, timestamp timestamp NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Retrieve all users and their associated wallet identifiers."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id"}, {"role": "user", "content": "Only show users whose username starts with 'J'."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%'"}, {"role": "user", "content": "Further filter to only include wallets where the address_id contains 'abc'."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%' AND T2.address_id LIKE '%abc%'"}, {"role": "user", "content": "For the filtered users and wallets, count how many wallets each user has."}, {"role": "assistant", "content": "SELECT T1.username , COUNT(T2.wallet_id) FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%' AND T2.address_id LIKE '%abc%' GROUP BY T1.username"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\n", "conversations": [{"role": "user", "content": "List all pairs of token transfers occurring within the same transaction where one transferred value is greater than the other, showing both transfer IDs, the transaction ID, and both values."}, {"role": "assistant", "content": "SELECT t1.transaction_id,\n t1.transfer_id AS transfer_id_1,\n t2.transfer_id AS transfer_id_2,\n t1.value AS value_1,\n t2.value AS value_2\nFROM web3.token_transfers t1\nJOIN web3.token_transfers t2\n ON t1.transaction_id = t2.transaction_id\n AND t1.value > t2.value;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\n", "conversations": [{"role": "user", "content": "List group conversation names and the count of messages sent in each conversation after '2024-06-01'."}, {"role": "assistant", "content": "SELECT T1.group_name, COUNT(T2.message_id) FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE AND T2.sent_at > '2024-06-01' GROUP BY T1.conversation_id, T1.group_name;"}, {"role": "user", "content": "Only show conversations that have more than 5 messages sent after that date."}, {"role": "assistant", "content": "SELECT T1.group_name, COUNT(T2.message_id) FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE AND T2.sent_at > '2024-06-01' GROUP BY T1.conversation_id, T1.group_name HAVING COUNT(T2.message_id) > 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\n", "conversations": [{"role": "user", "content": "List the first name, last name, and the name of the law firm for all lawyers."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id"}, {"role": "user", "content": "Now, filter this list to only include lawyers who work for firms founded after the year 2010."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T2.founded_date > '2010-12-31'"}, {"role": "user", "content": "For these lawyers, also include the firm's phone number and sort the results alphabetically by firm name."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name, T2.phone FROM lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T2.founded_date > '2010-12-31' ORDER BY T2.firm_name"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "List user IDs and the creation timestamp of likes made by users who have email notifications enabled."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true;"}, {"role": "user", "content": "Only show likes created in the year 2024."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01';"}, {"role": "user", "content": "Filter to only include users whose profile is not private."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01' AND T2.private_profile = false;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id.text, first_name.text, last_name.text, company_name.text, email.text, phone.text, address.text, date_registered.timestamp, status.text )\nCREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE TABLE legal_services.time_entries ( entry_id.text, case_id.text, lawyer_id.text, date_worked.date, hours_spent.numeric, billing_rate.numeric, description.text, is_billable.boolean, is_billed.boolean, invoice_id.text, created_at.timestamp )\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all documents along with the case number they are associated with, as well as the name and email of the lawyer who uploaded them."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id;"}, {"role": "user", "content": "Only include documents uploaded after April 1st, 2024."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01';"}, {"role": "user", "content": "Add the case name and make sure only documents with version greater than 1 are listed."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.cases c ON d.case_id = c.case_id JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01' AND d.version > 1;"}, {"role": "user", "content": "Order the results by upload_timestamp ascending."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email, d.upload_timestamp FROM legal_services.documents d JOIN legal_services.cases c ON d.case_id = c.case_id JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01' AND d.version > 1 ORDER BY d.upload_timestamp ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me each invoice and the invoice_number of the next invoice for the same client, along with how many days apart their issue_dates are."}, {"role": "assistant", "content": "SELECT a.invoice_number AS invoice_number,\n b.invoice_number AS next_invoice_number,\n (b.issue_date - a.issue_date) AS days_between\n FROM legal_services.invoices a\n JOIN legal_services.invoices b\n ON a.client_id = b.client_id\n AND b.issue_date > a.issue_date;"}, {"role": "user", "content": "Please restrict to pairs where the days_between is greater than 30."}, {"role": "assistant", "content": "SELECT a.invoice_number AS invoice_number,\n b.invoice_number AS next_invoice_number,\n (b.issue_date - a.issue_date) AS days_between\n FROM legal_services.invoices a\n JOIN legal_services.invoices b\n ON a.client_id = b.client_id\n AND b.issue_date > a.issue_date\n WHERE (b.issue_date - a.issue_date) > 30;"}, {"role": "user", "content": "And only include pairs where both invoices have status 'Overdue'."}, {"role": "assistant", "content": "SELECT a.invoice_number AS invoice_number,\n b.invoice_number AS next_invoice_number,\n (b.issue_date - a.issue_date) AS days_between\n FROM legal_services.invoices a\n JOIN legal_services.invoices b\n ON a.client_id = b.client_id\n AND b.issue_date > a.issue_date\n WHERE (b.issue_date - a.issue_date) > 30\n AND a.status = 'Overdue'\n AND b.status = 'Overdue';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.law_firms ( firm_id character varying(64) NOT NULL, firm_name character varying(200) NOT NULL, address text NOT NULL, phone character varying(32), website character varying(255), founded_date date, managing_partner_id character varying(64), PRIMARY KEY (firm_id) )\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Which lawyers have handled cases in the 'Federal Court' jurisdiction? Return each lawyer's first and last name, the case number, and the court jurisdiction."}, {"role": "assistant", "content": "SELECT l.first_name, l.last_name, c.case_number, c.court_jurisdiction\nFROM legal_services.lawyers l\nJOIN legal_services.cases c ON l.lawyer_id = c.lead_lawyer_id\nWHERE c.court_jurisdiction = 'Federal Court';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "How many appointments were created in the month of July 2024?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS appointment_count\nFROM legal_services.appointments\nWHERE DATE_TRUNC('month', created_at) = DATE '2024-07-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Count the total number of invoices issued in each calendar year and month. Show the year, month, and the count, ordered chronologically."}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM issue_date) AS issue_year, EXTRACT(MONTH FROM issue_date) AS issue_month, COUNT(*) AS invoice_count FROM legal_services.invoices GROUP BY issue_year, issue_month ORDER BY issue_year, issue_month;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "I need a list of each case_number and case_name with the total hours spent on each case based on time_entries, but only include cases where the total hours is greater than 10."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, SUM(te.hours_spent) AS total_hours\nFROM legal_services.cases c\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nGROUP BY c.case_number, c.case_name\nHAVING SUM(te.hours_spent) > 10;"}, {"role": "user", "content": "Actually, tally only hours where is_billable is true."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, SUM(te.hours_spent) AS total_hours\nFROM legal_services.cases c\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nWHERE te.is_billable = TRUE\nGROUP BY c.case_number, c.case_name\nHAVING SUM(te.hours_spent) > 10;"}, {"role": "user", "content": "Also include the client's first_name and last_name for each case."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, cl.first_name, cl.last_name, SUM(te.hours_spent) AS total_hours\nFROM legal_services.cases c\nJOIN legal_services.clients cl ON c.client_id = cl.client_id\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nWHERE te.is_billable = TRUE\nGROUP BY c.case_number, c.case_name, cl.first_name, cl.last_name\nHAVING SUM(te.hours_spent) > 10;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )\n", "conversations": [{"role": "user", "content": "List all law firms that do not have a website registered, including their firm name and phone."}, {"role": "assistant", "content": "SELECT firm_name, phone\nFROM legal_services.law_firms\nWHERE website IS NULL OR website = '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text 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.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n", "conversations": [{"role": "user", "content": "List the first and last names of all lawyers who have worked on time entries for cases associated with clients from the company 'Innovatech Ltd'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name FROM legal_services.lawyers AS T1 INNER JOIN legal_services.time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id INNER JOIN legal_services.cases AS T3 ON T2.case_id = T3.case_id INNER JOIN legal_services.clients AS T4 ON T3.client_id = T4.client_id WHERE T4.company_name = 'Innovatech Ltd';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "List all post IDs and their corresponding hashtag names for posts that include media."}, {"role": "assistant", "content": "SELECT ph.post_id, h.tag_name\nFROM social_media.post_hashtags ph\nJOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id\nJOIN social_media.posts p ON ph.post_id = p.post_id\nWHERE p.media_url IS NOT NULL AND p.media_url != '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )\n", "conversations": [{"role": "user", "content": "Show the username, full name, and location for all users who registered before January 1, 2024 and are not verified."}, {"role": "assistant", "content": "SELECT username, full_name, location FROM social_media.users WHERE created_at < '2024-01-01' AND is_verified = false;"}, {"role": "user", "content": "Only include those who have a non-empty location."}, {"role": "assistant", "content": "SELECT username, full_name, location FROM social_media.users WHERE created_at < '2024-01-01' AND is_verified = false AND location IS NOT NULL AND location <> '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.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) )\n", "conversations": [{"role": "user", "content": "List each account number and the total quantity of shares traded through it."}, {"role": "assistant", "content": "SELECT T2.account_number, SUM(T1.quantity) FROM financial_services.trades AS T1 JOIN financial_services.accounts AS T2 ON T1.account_id = T2.account_id GROUP BY 1"}, {"role": "user", "content": "Only include accounts with total quantity traded greater than 1000, and order the results by total quantity descending."}, {"role": "assistant", "content": "SELECT T2.account_number, SUM(T1.quantity) AS total_traded_quantity FROM financial_services.trades AS T1 JOIN financial_services.accounts AS T2 ON T1.account_id = T2.account_id GROUP BY 1 HAVING SUM(T1.quantity) > 1000 ORDER BY total_traded_quantity DESC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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) )\n", "conversations": [{"role": "user", "content": "Show me the total estimated loss per claim status, and for each status, include the most recent claim's incident date."}, {"role": "assistant", "content": "SELECT status, SUM(estimated_loss) AS total_estimated_loss, MAX(incident_date) AS most_recent_incident_date\nFROM insurance.claims\nGROUP BY status;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\n", "conversations": [{"role": "user", "content": "For each vehicle, can you show the vehicle_id, the number of unique fuel types it used, and the maximum quantity recorded in a single fuel log? Only include vehicles that have used more than one type of fuel."}, {"role": "assistant", "content": "SELECT vehicle_id, COUNT(DISTINCT fuel_type) AS unique_fuel_types, MAX(quantity) AS max_quantity\nFROM transportation.fuel_logs\nGROUP BY vehicle_id\nHAVING COUNT(DISTINCT fuel_type) > 1;"}, {"role": "user", "content": "Additionally, for these vehicles, please provide the total fuel cost for each vehicle."}, {"role": "assistant", "content": "SELECT vehicle_id, COUNT(DISTINCT fuel_type) AS unique_fuel_types, MAX(quantity) AS max_quantity, SUM(total_cost) AS total_fuel_cost\nFROM transportation.fuel_logs\nGROUP BY vehicle_id\nHAVING COUNT(DISTINCT fuel_type) > 1;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id text, post_id text, hashtag_id text )\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List the usernames of users who have created posts associated with any hashtag, and the name of the hashtag."}, {"role": "assistant", "content": "SELECT\n u.username,\n h.tag_name\nFROM social_media.users AS u\nJOIN social_media.posts AS p\n ON u.user_id = p.user_id\nJOIN social_media.post_hashtags AS ph\n ON p.post_id = ph.post_id\nJOIN social_media.hashtags AS h\n ON ph.hashtag_id = h.hashtag_id;"}, {"role": "user", "content": "Please refine the list to only include users who are verified."}, {"role": "assistant", "content": "SELECT\n u.username,\n h.tag_name\nFROM social_media.users AS u\nJOIN social_media.posts AS p\n ON u.user_id = p.user_id\nJOIN social_media.post_hashtags AS ph\n ON p.post_id = ph.post_id\nJOIN social_media.hashtags AS h\n ON ph.hashtag_id = h.hashtag_id\nWHERE\n u.is_verified = TRUE;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List the message_id, content, sender's username, and group_name for all messages in group chats."}, {"role": "assistant", "content": "SELECT m.message_id, m.content, u.username, c.group_name\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nWHERE c.is_group_chat = TRUE;"}, {"role": "user", "content": "Exclude group chats that have fewer than 3 participants."}, {"role": "assistant", "content": "SELECT m.message_id, m.content, u.username, c.group_name\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nJOIN (\n SELECT conversation_id\n FROM social_media.conversation_participants\n GROUP BY conversation_id\n HAVING COUNT(*) >= 3\n) cp ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = TRUE;"}, {"role": "user", "content": "And only show messages sent after '2024-06-01', ordering by sent_at ascending."}, {"role": "assistant", "content": "SELECT m.message_id, m.content, u.username, c.group_name\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nJOIN (\n SELECT conversation_id\n FROM social_media.conversation_participants\n GROUP BY conversation_id\n HAVING COUNT(*) >= 3\n) cp ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = TRUE\n AND m.sent_at > '2024-06-01'\nORDER BY m.sent_at ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claims ( claim_id 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) )\n", "conversations": [{"role": "user", "content": "List all claims that are still pending (status = 'pending') and were reported more than 30 days ago."}, {"role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, reported_date FROM insurance.claims WHERE status = 'pending' AND reported_date < CURRENT_DATE - INTERVAL '30 days';"}, {"role": "user", "content": "Now include only claims with estimated loss values and sort them by the oldest reported date first."}, {"role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, reported_date, estimated_loss FROM insurance.claims WHERE status = 'pending' AND reported_date < CURRENT_DATE - INTERVAL '30 days' AND estimated_loss IS NOT NULL ORDER BY reported_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.assets ( asset_id text PRIMARY KEY, name text, symbol text, type 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.logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the log entry\n user_id character varying(64), -- identifier of the user associated with the log entry\n action character varying(128) NOT NULL, -- action performed\n details text NOT NULL, -- details of the action\n logged_at timestamp NOT NULL, -- time when the log entry was created\n PRIMARY KEY (log_id)\n)\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "For each asset, show its name and the number of metadata entries associated with it, including assets with zero metadata, sorted by asset name ascending."}, {"role": "assistant", "content": "SELECT a.name, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.metadata m\n ON a.asset_id = m.asset_id\nGROUP BY a.name\nORDER BY a.name;"}, {"role": "user", "content": "Actually, I only want assets that have more than 3 metadata entries."}, {"role": "assistant", "content": "SELECT a.name, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.metadata m\n ON a.asset_id = m.asset_id\nGROUP BY a.name\nHAVING COUNT(m.metadata_id) > 3\nORDER BY a.name;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "List the full names of employees who have verified 'Proof of Identity' documents."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name FROM government_services.employees AS T1 JOIN government_services.documents AS T2 ON T1.employee_id = T2.verified_by_employee_id WHERE T2.document_type = 'Proof of Identity';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\n", "conversations": [{"role": "user", "content": "Show me the names and manufacturers of all medications that have a description provided."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NOT NULL;"}, {"role": "user", "content": "Now, only show those manufactured by 'Pfizer'."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NOT NULL AND manufacturer = 'Pfizer';"}, {"role": "user", "content": "Further filter to medications whose generic name contains 'statin'."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NOT NULL AND manufacturer = 'Pfizer' AND generic_name LIKE '%statin%';"}, {"role": "user", "content": "Instead, just show the medication ID and NDC code for these."}, {"role": "assistant", "content": "SELECT medication_id, ndc_code FROM healthcare.medications WHERE description IS NOT NULL AND manufacturer = 'Pfizer' AND generic_name LIKE '%statin%';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.prescriptions ( 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": "Show me all prescriptions made by doctors who have issued diagnoses described as 'Hypertension'. Include the doctor's ID, prescription ID, medication ID, and prescription date."}, {"role": "assistant", "content": "SELECT p.doctor_id, p.prescription_id, p.medication_id, p.prescription_date\nFROM healthcare.prescriptions p\nJOIN healthcare.diagnoses d ON p.doctor_id = d.doctor_id\nWHERE d.description = 'Hypertension';"}, {"role": "user", "content": "Change it to only include those prescriptions that started after January 1st, 2024."}, {"role": "assistant", "content": "SELECT p.doctor_id, p.prescription_id, p.medication_id, p.prescription_date\nFROM healthcare.prescriptions p\nJOIN healthcare.diagnoses d ON p.doctor_id = d.doctor_id\nWHERE d.description = 'Hypertension' AND p.start_date > '2024-01-01';"}, {"role": "user", "content": "Actually, also include the patient ID and only show results where the doctor's diagnosis of 'Hypertension' happened before the prescription start date."}, {"role": "assistant", "content": "SELECT p.doctor_id, p.patient_id, p.prescription_id, p.medication_id, p.prescription_date\nFROM healthcare.prescriptions p\nJOIN healthcare.diagnoses d ON p.doctor_id = d.doctor_id AND p.patient_id = d.patient_id\nWHERE d.description = 'Hypertension' AND p.start_date > '2024-01-01' AND d.diagnosis_date < p.start_date;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n", "conversations": [{"role": "user", "content": "Find all reservations where the total amount is greater than 500 and they have at least one service order. Show the reservation ID and the total amount."}, {"role": "assistant", "content": "SELECT DISTINCT T1.reservation_id, T1.total_amount FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.reservation_id = T2.reservation_id WHERE T1.total_amount > 500;"}, {"role": "user", "content": "Actually, also include the number of service orders for each of these reservations and the total price of those service orders."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T1.total_amount, COUNT(T2.order_id), SUM(T2.total_price) FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.reservation_id = T2.reservation_id WHERE T1.total_amount > 500 GROUP BY T1.reservation_id, T1.total_amount;"}, {"role": "user", "content": "Only show reservations where the total price of the service orders is more than 100."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T1.total_amount, COUNT(T2.order_id), SUM(T2.total_price) FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.reservation_id = T2.reservation_id WHERE T1.total_amount > 500 GROUP BY T1.reservation_id, T1.total_amount HAVING SUM(T2.total_price) > 100;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )\n", "conversations": [{"role": "user", "content": "Show me law firms that were founded after 2018 and have a website provided."}, {"role": "assistant", "content": "SELECT firm_name, founded_date, website\nFROM legal_services.law_firms\nWHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '';"}, {"role": "user", "content": "Actually, only include firms where the phone number starts with '+1'."}, {"role": "assistant", "content": "SELECT firm_name, founded_date, website, phone\nFROM legal_services.law_firms\nWHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '' AND phone LIKE '+1%';"}, {"role": "user", "content": "Also add the firm address and sort the results by founded_date descending."}, {"role": "assistant", "content": "SELECT firm_name, founded_date, website, phone, address\nFROM legal_services.law_firms\nWHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '' AND phone LIKE '+1%'\nORDER BY founded_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 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.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n", "conversations": [{"role": "user", "content": "I need a list of all chronic diagnoses marked as 'Active', showing diagnosis_id, diagnosis_date, doctor_id, and the associated chief_complaint from medical_records."}, {"role": "assistant", "content": "SELECT d.diagnosis_id,\n d.diagnosis_date,\n d.doctor_id,\n m.chief_complaint\nFROM healthcare.diagnoses d\nJOIN healthcare.medical_records m\n ON d.record_id = m.record_id\nWHERE d.is_chronic = TRUE\n AND d.status = 'Active';"}, {"role": "user", "content": "Actually, only include those diagnoses that occurred in February 2024 and order the results by diagnosis_date ascending."}, {"role": "assistant", "content": "SELECT d.diagnosis_id,\n d.diagnosis_date,\n d.doctor_id,\n m.chief_complaint\nFROM healthcare.diagnoses d\nJOIN healthcare.medical_records m\n ON d.record_id = m.record_id\nWHERE d.is_chronic = TRUE\n AND d.status = 'Active'\n AND d.diagnosis_date BETWEEN '2024-02-01' AND '2024-02-29'\nORDER BY d.diagnosis_date ASC;"}, {"role": "user", "content": "Also, include the assessment column from medical_records in the output."}, {"role": "assistant", "content": "SELECT d.diagnosis_id,\n d.diagnosis_date,\n d.doctor_id,\n m.chief_complaint,\n m.assessment\nFROM healthcare.diagnoses d\nJOIN healthcare.medical_records m\n ON d.record_id = m.record_id\nWHERE d.is_chronic = TRUE\n AND d.status = 'Active'\n AND d.diagnosis_date BETWEEN '2024-02-01' AND '2024-02-29'\nORDER BY d.diagnosis_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.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 ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the top 5 users who have the highest total trade volume (quantity * price) as buyers, along with their wallet addresses and the number of distinct assets they traded."}, {"role": "assistant", "content": "SELECT t.buyer_id, w.address, COUNT(DISTINCT t.asset_id) AS distinct_assets, SUM(t.quantity * t.price) AS total_volume FROM trading_platform.trades t JOIN trading_platform.wallets w ON t.buyer_id = w.user_id GROUP BY t.buyer_id, w.address ORDER BY total_volume DESC LIMIT 5;"}, {"role": "user", "content": "Now modify the query to only include trades that happened in the last 30 days and show the average trade price for each buyer."}, {"role": "assistant", "content": "SELECT t.buyer_id, w.address, COUNT(DISTINCT t.asset_id) AS distinct_assets, SUM(t.quantity * t.price) AS total_volume, AVG(t.price) AS avg_price FROM trading_platform.trades t JOIN trading_platform.wallets w ON t.buyer_id = w.user_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY t.buyer_id, w.address ORDER BY total_volume DESC LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the top 5 buyers by total trade volume who also have at least 3 distinct assets traded, and include their wallet creation date."}, {"role": "assistant", "content": "SELECT t.buyer_id, w.address, COUNT(DISTINCT t.asset_id) AS distinct_assets, SUM(t.quantity * t.price) AS total_volume, AVG(t.price) AS avg_price, w.created_at AS wallet_created FROM trading_platform.trades t JOIN trading_platform.wallets w ON t.buyer_id = w.user_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY t.buyer_id, w.address, w.created_at HAVING COUNT(DISTINCT t.asset_id) >= 3 ORDER BY total_volume DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "For each fuel_type, can you calculate the total total_cost and the average total_cost from the fuel_logs table?"}, {"role": "assistant", "content": "SELECT fuel_type,\n SUM(total_cost) AS total_cost_sum,\n AVG(total_cost) AS average_cost\nFROM transportation.fuel_logs\nGROUP BY fuel_type;"}, {"role": "user", "content": "Please exclude any fuel_type with fewer than 5 fuel log entries."}, {"role": "assistant", "content": "SELECT fuel_type,\n SUM(total_cost) AS total_cost_sum,\n AVG(total_cost) AS average_cost\nFROM transportation.fuel_logs\nGROUP BY fuel_type\nHAVING COUNT(*) >= 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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.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 user, list their username and the total number of filled orders they have placed."}, {"role": "assistant", "content": "SELECT u.username, COUNT(o.order_id) AS filled_order_count\nFROM trading_platform.users u\nJOIN trading_platform.orders o ON u.user_id = o.user_id\nWHERE o.status = 'filled'\nGROUP BY u.username;"}, {"role": "user", "content": "Now only include users who have placed more than 10 filled orders."}, {"role": "assistant", "content": "SELECT u.username, COUNT(o.order_id) AS filled_order_count\nFROM trading_platform.users u\nJOIN trading_platform.orders o ON u.user_id = o.user_id\nWHERE o.status = 'filled'\nGROUP BY u.username\nHAVING COUNT(o.order_id) > 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text )\n", "conversations": [{"role": "user", "content": "Find pairs of notifications for the same citizen where one was sent via 'Email' and another via 'SMS'. Display citizen_id, email_notification_id, sms_notification_id, email_sent_at, and sms_sent_at."}, {"role": "assistant", "content": "SELECT e.citizen_id,\n e.notification_id AS email_notification_id,\n s.notification_id AS sms_notification_id,\n e.sent_at AS email_sent_at,\n s.sent_at AS sms_sent_at\nFROM government_services.notifications e\nJOIN government_services.notifications s\n ON e.citizen_id = s.citizen_id\n AND e.channel = 'Email'\n AND s.channel = 'SMS';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id.text, address.text, abi.text, bytecode.text, deployer_address.text, deployed_at.timestamp, network_id.text, status.text )\nCREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )\nCREATE TABLE web3.token_transfers ( transfer_id.text, token_id.text, from_address.text, to_address.text, value.numeric, transaction_id.text, log_index.integer )\nCREATE TABLE web3.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\nCREATE TABLE web3.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List the transaction IDs that have both an event and a token transfer, along with the name of the event and the value of the token transfer."}, {"role": "assistant", "content": "SELECT T1.transaction_id, T1.event_name, T2.value FROM web3.events AS T1 JOIN web3.token_transfers AS T2 ON T1.transaction_id = T2.transaction_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE manufacturing.materials (\n material_id character varying(64) NOT NULL, -- unique identifier for the material\n material_name character varying(128) NOT NULL, -- common name (e.g., Titanium Alloy Grade 5, Carbon Fiber Prepreg)\n specification character varying(255), -- specification standard (e.g., AMS 4928)\n description text, -- detailed description of properties\n density_kg_m3 numeric(10, 4), -- density in kg per cubic meter\n tensile_strength_mpa integer, -- tensile strength in Megapascals\n PRIMARY KEY (material_id)\n)\nCREATE TABLE manufacturing.assembly_steps (\n step_id character varying(64) NOT NULL, -- unique identifier for an assembly step/task\n line_id character varying(64) NOT NULL, -- FK to the assembly line where this step occurs\n step_number integer NOT NULL, -- sequence number of the step on the line\n step_name character varying(255) NOT NULL, -- name of the task (e.g., Install Wing Root Fairing)\n description text, -- detailed instructions or description\n standard_duration_hours numeric(8,2), -- estimated time to complete the step\n required_skill_level character varying(50), -- skill level needed (e.g., 'Mechanic II', 'Electrician I')\n workstation character varying(100), -- specific workstation or area for the step\n PRIMARY KEY (step_id)\n)\n", "conversations": [{"role": "user", "content": "\u7279\u5b9a\u306e\u6750\u6599\u306e\u8a73\u7d30\u60c5\u5831\u3092\u53d6\u5f97\u3057\u305f\u3044\u3067\u3059\u3002\u6750\u6599ID\u3001\u6750\u6599\u540d\u3001\u4ed5\u69d8\u3001\u5bc6\u5ea6\u3092\u53d6\u5f97\u3057\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SELECT material_id, material_name, specification, density_kg_m3\nFROM manufacturing.materials\nWHERE material_id = 'specific_material_id';"}, {"role": "user", "content": "\u3055\u3089\u306b\u3001\u5f15\u5f35\u5f37\u5ea6\u304c500MPa\u4ee5\u4e0a\u306e\u6750\u6599\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3067\u304d\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SELECT material_id, material_name, specification, density_kg_m3\nFROM manufacturing.materials\nWHERE material_id = 'specific_material_id'\nAND tensile_strength_mpa >= 500;"}, {"role": "user", "content": "\u3082\u3057\u5bc6\u5ea6\u304c2000kg/m3\u672a\u6e80\u306e\u6750\u6599\u3092\u9664\u5916\u3057\u305f\u3044\u5834\u5408\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SELECT material_id, material_name, specification, density_kg_m3\nFROM manufacturing.materials\nWHERE material_id = 'specific_material_id'\nAND tensile_strength_mpa >= 500\nAND density_kg_m3 >= 2000;"}, {"role": "user", "content": "\u6700\u5f8c\u306b\u3001\u6750\u6599\u540d\u3092\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\u306b\u4e26\u3079\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SELECT material_id, material_name, specification, density_kg_m3\nFROM manufacturing.materials\nWHERE material_id = 'specific_material_id'\nAND tensile_strength_mpa >= 500\nAND density_kg_m3 >= 2000\nORDER BY material_name;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\n", "conversations": [{"role": "user", "content": "I need to list pairs of achievements within the same game, showing game_id, the name of the first achievement, and the name of the second achievement."}, {"role": "assistant", "content": "SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2\nFROM gaming_technology.achievements a1\nJOIN gaming_technology.achievements a2\n ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id;"}, {"role": "user", "content": "Exclude any pairs where either achievement is hidden."}, {"role": "assistant", "content": "SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2\nFROM gaming_technology.achievements a1\nJOIN gaming_technology.achievements a2\n ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id\nWHERE a1.hidden = FALSE AND a2.hidden = FALSE;"}, {"role": "user", "content": "Only include pairs where the absolute difference in points between the two achievements is greater than 50."}, {"role": "assistant", "content": "SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2\nFROM gaming_technology.achievements a1\nJOIN gaming_technology.achievements a2\n ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id\nWHERE a1.hidden = FALSE AND a2.hidden = FALSE\n AND ABS(a1.points - a2.points) > 50;"}, {"role": "user", "content": "Finally, order the results by the points difference in descending order."}, {"role": "assistant", "content": "SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2\nFROM gaming_technology.achievements a1\nJOIN gaming_technology.achievements a2\n ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id\nWHERE a1.hidden = FALSE AND a2.hidden = FALSE\n AND ABS(a1.points - a2.points) > 50\nORDER BY ABS(a1.points - a2.points) DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.metadata ( metadata_id 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": "Show each asset's symbol and the number of unique addresses that have UTXOs associated with it."}, {"role": "assistant", "content": "SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses\nFROM trading_platform.assets a\nJOIN trading_platform.utxos u ON a.asset_id = u.transaction_id\nGROUP BY a.asset_id, a.symbol;"}, {"role": "user", "content": "Now show only assets with more than 5 unique addresses."}, {"role": "assistant", "content": "SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses\nFROM trading_platform.assets a\nJOIN trading_platform.utxos u ON a.asset_id = u.transaction_id\nGROUP BY a.asset_id, a.symbol\nHAVING COUNT(DISTINCT u.address) > 5;"}, {"role": "user", "content": "Please also include the total amount for each asset in the result."}, {"role": "assistant", "content": "SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses, COALESCE(SUM(u.amount), 0) AS total_amount\nFROM trading_platform.assets a\nJOIN trading_platform.utxos u ON a.asset_id = u.transaction_id\nGROUP BY a.asset_id, a.symbol\nHAVING COUNT(DISTINCT u.address) > 5;"}, {"role": "user", "content": "Order the results by total_amount ascending and limit to the top 3."}, {"role": "assistant", "content": "SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses, COALESCE(SUM(u.amount), 0) AS total_amount\nFROM trading_platform.assets a\nJOIN trading_platform.utxos u ON a.asset_id = u.transaction_id\nGROUP BY a.asset_id, a.symbol\nHAVING COUNT(DISTINCT u.address) > 5\nORDER BY total_amount ASC\nLIMIT 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\n", "conversations": [{"role": "user", "content": "Which medications do not have a generic name listed? Show their medication_id, medication_name, and manufacturer."}, {"role": "assistant", "content": "SELECT medication_id, medication_name, manufacturer FROM healthcare.medications WHERE generic_name IS NULL OR generic_name = '';"}, {"role": "user", "content": "Could you also include the description for each medication?"}, {"role": "assistant", "content": "SELECT medication_id, medication_name, manufacturer, description FROM healthcare.medications WHERE generic_name IS NULL OR generic_name = '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )\n", "conversations": [{"role": "user", "content": "Find pairs of items within the same game where the cost of one item is at least 10 times the cost of the other. Show the game ID, the name of the more expensive item, and the name of the less expensive item."}, {"role": "assistant", "content": "SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id;"}, {"role": "user", "content": "Only include pairs where both items are of rarity 'Rare' or higher (i.e., 'Rare', 'Epic', 'Legendary')."}, {"role": "assistant", "content": "SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id AND i1.rarity IN ('Rare', 'Epic', 'Legendary') AND i2.rarity IN ('Rare', 'Epic', 'Legendary');"}, {"role": "user", "content": "Exclude pairs where either item's cost is 0."}, {"role": "assistant", "content": "SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id AND i1.rarity IN ('Rare', 'Epic', 'Legendary') AND i2.rarity IN ('Rare', 'Epic', 'Legendary') AND i1.cost_amount > 0 AND i2.cost_amount > 0;"}, {"role": "user", "content": "Order the results by the game ID and then by the cost of the expensive item descending."}, {"role": "assistant", "content": "SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id AND i1.rarity IN ('Rare', 'Epic', 'Legendary') AND i2.rarity IN ('Rare', 'Epic', 'Legendary') AND i1.cost_amount > 0 AND i2.cost_amount > 0 ORDER BY i1.game_id, i1.cost_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\nCREATE TABLE insurance.premium_payments ( payment_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, amount_paid numeric(12, 2) NOT NULL, payment_method character varying(50), transaction_reference character varying(128) UNIQUE, due_date date, payment_period_start date, payment_period_end date, status character varying(30) NOT NULL DEFAULT 'Completed', PRIMARY KEY (payment_id) )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "Count the number of customers grouped by their status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM insurance.customers GROUP BY status;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 guests who have written reviews, showing their full name and the review comment."}, {"role": "assistant", "content": "SELECT g.first_name || ' ' || g.last_name AS guest_full_name, r.comment FROM hospitality_technology.guests AS g JOIN hospitality_technology.reviews AS r ON g.guest_id = r.guest_id;"}, {"role": "user", "content": "Now only include reviews with an overall rating of 5."}, {"role": "assistant", "content": "SELECT g.first_name || ' ' || g.last_name AS guest_full_name, r.comment FROM hospitality_technology.guests AS g JOIN hospitality_technology.reviews AS r ON g.guest_id = r.guest_id WHERE r.rating_overall = 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 )\n", "conversations": [{"role": "user", "content": "Find all doctors who have a hospital affiliation and include their full names (concatenated), specialties, and affiliation IDs."}, {"role": "assistant", "content": "SELECT CONCAT(first_name, ' ', last_name) AS full_name, specialty, hospital_affiliation_id FROM healthcare.doctors WHERE hospital_affiliation_id IS NOT NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "Give me the number of securities and the latest update timestamp for each security_type."}, {"role": "assistant", "content": "SELECT security_type,\n COUNT(*) AS security_count,\n MAX(last_updated) AS latest_update\nFROM financial_services.securities\nGROUP BY security_type;"}, {"role": "user", "content": "Now only show types with more than 10 securities."}, {"role": "assistant", "content": "SELECT security_type,\n COUNT(*) AS security_count,\n MAX(last_updated) AS latest_update\nFROM financial_services.securities\nGROUP BY security_type\nHAVING COUNT(*) > 10;"}, {"role": "user", "content": "Sort the output by latest_update ascending."}, {"role": "assistant", "content": "SELECT security_type,\n COUNT(*) AS security_count,\n MAX(last_updated) AS latest_update\nFROM financial_services.securities\nGROUP BY security_type\nHAVING COUNT(*) > 10\nORDER BY latest_update ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America/New_York)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings (\n booking_id character varying(64) NOT NULL, -- unique identifier for the booking\n passenger_id character varying(64) NOT NULL, -- identifier of the passenger making the booking\n trip_id character varying(64) NOT NULL, -- identifier of the trip being booked\n seat_number character varying(16), -- assigned seat number (if applicable)\n booking_time timestamp with time zone NOT NULL, -- time when the booking was made\n status character varying(32) NOT NULL, -- e.g., Confirmed, Cancelled, Pending Payment\n fare numeric(10, 2) NOT NULL, -- price paid for the booking\n payment_transaction_id character varying(128), -- reference to the payment transaction\n special_requests text, -- any special requests from the passenger\n PRIMARY KEY (booking_id)\n)\n", "conversations": [{"role": "user", "content": "For each passenger, show their full name and the total amount they have spent on completed bookings."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, SUM(b.fare) AS total_spent\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.status = 'Completed'\nGROUP BY p.passenger_id, p.first_name, p.last_name;"}, {"role": "user", "content": "Can you also include the number of completed bookings for each passenger?"}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS completed_bookings, SUM(b.fare) AS total_spent\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.status = 'Completed'\nGROUP BY p.passenger_id, p.first_name, p.last_name;"}, {"role": "user", "content": "Only include passengers who have spent more than 300 in total."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS completed_bookings, SUM(b.fare) AS total_spent\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.status = 'Completed'\nGROUP BY p.passenger_id, p.first_name, p.last_name\nHAVING SUM(b.fare) > 300;"}, {"role": "user", "content": "I got an error about missing the email, please add their email to the output."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, p.email, COUNT(b.booking_id) AS completed_bookings, SUM(b.fare) AS total_spent\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.status = 'Completed'\nGROUP BY p.passenger_id, p.first_name, p.last_name, p.email\nHAVING SUM(b.fare) > 300;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n", "conversations": [{"role": "user", "content": "List all insurance products along with their product type and creation date."}, {"role": "assistant", "content": "SELECT product_name, product_type, created_at\nFROM insurance.insurance_products;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n \"CREATE TABLE 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": "List the top 3 tokens by liquidity on BSC and show their token symbols, prices, market cap, and liquidity."}, {"role": "assistant", "content": "SELECT token_symbol, price, market_cap, liquidity\nFROM token_dexpool_info\nWHERE chain = 'BSC'\nORDER BY liquidity DESC\nLIMIT 3;"}, {"role": "user", "content": "Could you also include the 24-hour price change percentage and 24-hour trading volume for these tokens?"}, {"role": "assistant", "content": "SELECT token_symbol, price, market_cap, liquidity, price_change_percentage_24h, volume_24h\nFROM token_dexpool_info\nWHERE chain = 'BSC'\nORDER BY liquidity DESC\nLIMIT 3;"}, {"role": "user", "content": "Show only those tokens with positive 6-hour and 24-hour price change percentages."}, {"role": "assistant", "content": "SELECT token_symbol, price, market_cap, liquidity, price_change_percentage_24h, volume_24h\nFROM token_dexpool_info\nWHERE chain = 'BSC'\n AND price_change_percentage_6h > 0\n AND price_change_percentage_24h > 0\nORDER BY liquidity DESC\nLIMIT 3;"}, {"role": "user", "content": "Now include the makers_24h for each result."}, {"role": "assistant", "content": "SELECT token_symbol, price, market_cap, liquidity, price_change_percentage_24h, volume_24h, makers_24h\nFROM token_dexpool_info\nWHERE chain = 'BSC'\n AND price_change_percentage_6h > 0\n AND price_change_percentage_24h > 0\nORDER BY liquidity DESC\nLIMIT 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.agents ( agent_id text, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n", "conversations": [{"role": "user", "content": "List all active agents with the number of open claims they've handled and the average settlement amount for their closed claims. Include agent_id, first_name, last_name, open_claims_count, and avg_settlement_closed."}, {"role": "assistant", "content": "SELECT a.agent_id, a.first_name, a.last_name,\n COUNT(CASE WHEN c.status = 'Open' THEN 1 END) AS open_claims_count,\n AVG(CASE WHEN c.status = 'Closed' THEN c.settlement_amount END) AS avg_settlement_closed\nFROM insurance.agents a\nLEFT JOIN insurance.claims c ON a.agent_id = c.claim_handler_id\nWHERE a.status = 'Active'\nGROUP BY a.agent_id, a.first_name, a.last_name;"}, {"role": "user", "content": "Actually, only include agents with more than 5 open claims, and also include their total number of closed claims as closed_claims_count."}, {"role": "assistant", "content": "SELECT a.agent_id, a.first_name, a.last_name,\n COUNT(CASE WHEN c.status = 'Open' THEN 1 END) AS open_claims_count,\n SUM(CASE WHEN c.status = 'Closed' THEN 1 END) AS closed_claims_count,\n AVG(CASE WHEN c.status = 'Closed' THEN c.settlement_amount END) AS avg_settlement_closed\nFROM insurance.agents a\nLEFT JOIN insurance.claims c ON a.agent_id = c.claim_handler_id\nWHERE a.status = 'Active'\nGROUP BY a.agent_id, a.first_name, a.last_name\nHAVING COUNT(CASE WHEN c.status = 'Open' THEN 1 END) > 5;"}, {"role": "user", "content": "Also, sort the results by avg_settlement_closed descending and limit to the top 10 agents."}, {"role": "assistant", "content": "SELECT a.agent_id, a.first_name, a.last_name,\n COUNT(CASE WHEN c.status = 'Open' THEN 1 END) AS open_claims_count,\n SUM(CASE WHEN c.status = 'Closed' THEN 1 END) AS closed_claims_count,\n AVG(CASE WHEN c.status = 'Closed' THEN c.settlement_amount END) AS avg_settlement_closed\nFROM insurance.agents a\nLEFT JOIN insurance.claims c ON a.agent_id = c.claim_handler_id\nWHERE a.status = 'Active'\nGROUP BY a.agent_id, a.first_name, a.last_name\nHAVING COUNT(CASE WHEN c.status = 'Open' THEN 1 END) > 5\nORDER BY avg_settlement_closed DESC\nLIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.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 )\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all users who currently have a 'pending' KYC status, showing their user ID and username."}, {"role": "assistant", "content": "SELECT u.user_id, u.username FROM users u JOIN kyc_audit k ON u.user_id = k.user_id WHERE k.status = 'pending';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all clients along with the total number of invoices they have and the sum of total_amount for those invoices."}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv ON cl.client_id = inv.client_id\nGROUP BY cl.client_id, cl.first_name, cl.last_name;"}, {"role": "user", "content": "Could you limit this to invoices issued after '2023-01-01'?"}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv\n ON cl.client_id = inv.client_id AND inv.issue_date > '2023-01-01'\nGROUP BY cl.client_id, cl.first_name, cl.last_name;"}, {"role": "user", "content": "Also exclude clients who haven't paid any invoice."}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv\n ON cl.client_id = inv.client_id AND inv.issue_date > '2023-01-01'\nGROUP BY cl.client_id, cl.first_name, cl.last_name\nHAVING SUM(inv.amount_paid) > 0;"}, {"role": "user", "content": "Sort the results by sum_total_amount descending."}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv\n ON cl.client_id = inv.client_id AND inv.issue_date > '2023-01-01'\nGROUP BY cl.client_id, cl.first_name, cl.last_name\nHAVING SUM(inv.amount_paid) > 0\nORDER BY sum_total_amount DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\n", "conversations": [{"role": "user", "content": "List the latest version of each document (identified by case_id and document_name), showing the version number and its upload_timestamp."}, {"role": "assistant", "content": "SELECT d.case_id,\n d.document_name,\n d.version AS latest_version,\n d.upload_timestamp\nFROM legal_services.documents d\nJOIN (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m ON d.case_id = m.case_id\n AND d.document_name = m.document_name\n AND d.version = m.max_version;"}, {"role": "user", "content": "Actually, I also want to see the upload_timestamp of the previous version for each document."}, {"role": "assistant", "content": "SELECT m.case_id,\n m.document_name,\n m.max_version AS latest_version,\n d_latest.upload_timestamp AS latest_timestamp,\n d_prev.upload_timestamp AS previous_timestamp\nFROM (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m\nJOIN legal_services.documents d_latest\n ON d_latest.case_id = m.case_id\n AND d_latest.document_name = m.document_name\n AND d_latest.version = m.max_version\nLEFT JOIN legal_services.documents d_prev\n ON d_prev.case_id = m.case_id\n AND d_prev.document_name = m.document_name\n AND d_prev.version = m.max_version - 1;"}, {"role": "user", "content": "Also, only include documents whose first version (version = 1) was uploaded in 2024."}, {"role": "assistant", "content": "SELECT m.case_id,\n m.document_name,\n m.max_version AS latest_version,\n d_latest.upload_timestamp AS latest_timestamp,\n d_prev.upload_timestamp AS previous_timestamp\nFROM (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m\nJOIN legal_services.documents d_first\n ON d_first.case_id = m.case_id\n AND d_first.document_name = m.document_name\n AND d_first.version = 1\n AND d_first.upload_timestamp >= '2024-01-01'\n AND d_first.upload_timestamp < '2025-01-01'\nJOIN legal_services.documents d_latest\n ON d_latest.case_id = m.case_id\n AND d_latest.document_name = m.document_name\n AND d_latest.version = m.max_version\nLEFT JOIN legal_services.documents d_prev\n ON d_prev.case_id = m.case_id\n AND d_prev.document_name = m.document_name\n AND d_prev.version = m.max_version - 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "For each client, list their first and last invoice numbers along with the corresponding issue_dates."}, {"role": "assistant", "content": "SELECT first_inv.client_id,\n first_inv.invoice_number AS first_invoice,\n first_inv.issue_date AS first_date,\n last_inv.invoice_number AS last_invoice,\n last_inv.issue_date AS last_date\nFROM legal_services.invoices first_inv\nJOIN legal_services.invoices last_inv\n ON first_inv.client_id = last_inv.client_id\n AND first_inv.issue_date = (\n SELECT MIN(issue_date)\n FROM legal_services.invoices\n WHERE client_id = first_inv.client_id\n )\n AND last_inv.issue_date = (\n SELECT MAX(issue_date)\n FROM legal_services.invoices\n WHERE client_id = last_inv.client_id\n );"}, {"role": "user", "content": "Sort the output by client_id."}, {"role": "assistant", "content": "SELECT first_inv.client_id,\n first_inv.invoice_number AS first_invoice,\n first_inv.issue_date AS first_date,\n last_inv.invoice_number AS last_invoice,\n last_inv.issue_date AS last_date\nFROM legal_services.invoices first_inv\nJOIN legal_services.invoices last_inv\n ON first_inv.client_id = last_inv.client_id\n AND first_inv.issue_date = (\n SELECT MIN(issue_date)\n FROM legal_services.invoices\n WHERE client_id = first_inv.client_id\n )\n AND last_inv.issue_date = (\n SELECT MAX(issue_date)\n FROM legal_services.invoices\n WHERE client_id = last_inv.client_id\n )\nORDER BY first_inv.client_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the invoice number and total amount for invoices, along with the case number and case name for the related case."}, {"role": "assistant", "content": "SELECT i.invoice_number, i.total_amount, c.case_number, c.case_name\nFROM legal_services.invoices i\nJOIN legal_services.cases c ON i.case_id = c.case_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\n", "conversations": [{"role": "user", "content": "Show me the total amount and number of unique holder wallets for each ERC20 token held on Ethereum. Please display contract address, sum of amounts, and holder count."}, {"role": "assistant", "content": "SELECT contract_address, SUM(amount::numeric) AS total_amount, COUNT(DISTINCT wallet_address) AS holder_count\nFROM erc20_balances\nGROUP BY contract_address;"}, {"role": "user", "content": "Add the token symbol and decimals for each contract by joining with token_prices_latest."}, {"role": "assistant", "content": "SELECT eb.contract_address, SUM(eb.amount::numeric) AS total_amount, COUNT(DISTINCT eb.wallet_address) AS holder_count, t.symbol, t.decimals\nFROM erc20_balances eb\nLEFT JOIN token_prices_latest t ON eb.contract_address = t.address AND t.blockchain = 'Ethereum'\nGROUP BY eb.contract_address, t.symbol, t.decimals;"}, {"role": "user", "content": "Filter to only include tokens with more than 300 holders and order by total amount descending."}, {"role": "assistant", "content": "SELECT eb.contract_address, SUM(eb.amount::numeric) AS total_amount, COUNT(DISTINCT eb.wallet_address) AS holder_count, t.symbol, t.decimals\nFROM erc20_balances eb\nLEFT JOIN token_prices_latest t ON eb.contract_address = t.address AND t.blockchain = 'Ethereum'\nGROUP BY eb.contract_address, t.symbol, t.decimals\nHAVING COUNT(DISTINCT eb.wallet_address) > 300\nORDER BY total_amount DESC;"}, {"role": "user", "content": "Limit the result to the top 10 tokens only."}, {"role": "assistant", "content": "SELECT eb.contract_address, SUM(eb.amount::numeric) AS total_amount, COUNT(DISTINCT eb.wallet_address) AS holder_count, t.symbol, t.decimals\nFROM erc20_balances eb\nLEFT JOIN token_prices_latest t ON eb.contract_address = t.address AND t.blockchain = 'Ethereum'\nGROUP BY eb.contract_address, t.symbol, t.decimals\nHAVING COUNT(DISTINCT eb.wallet_address) > 300\nORDER BY total_amount DESC\nLIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "For each Bitcoin token tick, show me the creator address from the token_info_bitcoin table and the number of unique wallets currently holding that token."}, {"role": "assistant", "content": "SELECT ti.tick, ti.creator, COUNT(DISTINCT tb.wallet_address) AS unique_wallets FROM token_info_bitcoin ti JOIN token_balances_bitcoin tb ON ti.tick = tb.tick GROUP BY ti.tick, ti.creator;"}, {"role": "user", "content": "Now, only include ticks where there are more than 5 unique wallets, and order the result by the number of unique wallets descending."}, {"role": "assistant", "content": "SELECT ti.tick, ti.creator, COUNT(DISTINCT tb.wallet_address) AS unique_wallets FROM token_info_bitcoin ti JOIN token_balances_bitcoin tb ON ti.tick = tb.tick GROUP BY ti.tick, ti.creator HAVING COUNT(DISTINCT tb.wallet_address) > 5 ORDER BY unique_wallets DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\n", "conversations": [{"role": "user", "content": "For each ERC1155 NFT on Ethereum, can you show the contract address, token ID, and the total number of unique wallet holders?"}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, COUNT(DISTINCT nh.wallet_address) AS unique_holders\nFROM nft_holders nh\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id;"}, {"role": "user", "content": "Can you also include the total amount held for each NFT across all wallets?"}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, COUNT(DISTINCT nh.wallet_address) AS unique_holders, SUM(CAST(nh.amount AS BIGINT)) AS total_amount\nFROM nft_holders nh\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id;"}, {"role": "user", "content": "I want the result restricted to NFTs where the total amount held is more than 1000."}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, COUNT(DISTINCT nh.wallet_address) AS unique_holders, SUM(CAST(nh.amount AS BIGINT)) AS total_amount\nFROM nft_holders nh\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id\nHAVING SUM(CAST(nh.amount AS BIGINT)) > 1000;"}, {"role": "user", "content": "Please also add the name of each NFT from the nft_metadata table, if available."}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, nm.name AS nft_name, COUNT(DISTINCT nh.wallet_address) AS unique_holders, SUM(CAST(nh.amount AS BIGINT)) AS total_amount\nFROM nft_holders nh\nLEFT JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id AND nm.blockchain = 'Ethereum'\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id, nm.name\nHAVING SUM(CAST(nh.amount AS BIGINT)) > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\n", "conversations": [{"role": "user", "content": "Show all SUI coins with 'exists' status and more than 8 decimal places. Display coin_type, symbol, name, and decimals."}, {"role": "assistant", "content": "SELECT coin_type, symbol, name, decimals\nFROM sui_coins_metadata\nWHERE status = 'exists' AND decimals > 8;"}, {"role": "user", "content": "Add the total balance for each coin_type by joining with sui_coins."}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, SUM(sc.balance::numeric) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND scm.decimals > 8\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals;"}, {"role": "user", "content": "Can you also include only coins where the total_balance is greater than 1,000,000 and show the description?"}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description, SUM(sc.balance::numeric) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND scm.decimals > 8\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description\nHAVING SUM(sc.balance::numeric) > 1000000;"}, {"role": "user", "content": "Actually, only show the top 5 coins with the highest total_balance."}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description, SUM(sc.balance::numeric) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND scm.decimals > 8\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description\nHAVING SUM(sc.balance::numeric) > 1000000\nORDER BY total_balance DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE token_prices (\n uuid varchar(36) NOT NULL, -- uuid fields for the functionType in contract\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "Show me the wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount, from the erc20_balances table."}, {"role": "assistant", "content": "SELECT e.wallet_address, t.symbol, e.amount FROM erc20_balances e JOIN token_prices_latest t ON e.contract_address = t.address WHERE CAST(e.amount AS decimal) > 1000;"}, {"role": "user", "content": "Can you also include the current price of each token from the token_prices_latest table and sort the results by amount in descending order?"}, {"role": "assistant", "content": "SELECT e.wallet_address, t.symbol, e.amount, t.price FROM erc20_balances e JOIN token_prices_latest t ON e.contract_address = t.address WHERE CAST(e.amount AS decimal) > 1000 ORDER BY CAST(e.amount AS decimal) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "List the ERC20 tokens (from token_metas) with exactly 6 decimals. Show their symbol, contract_address, and name."}, {"role": "assistant", "content": "SELECT symbol, contract_address, name FROM token_metas WHERE is_erc20 = 1 AND decimals = 6;"}, {"role": "user", "content": "Can you also include the total current supply for each token?"}, {"role": "assistant", "content": "SELECT symbol, contract_address, name, total_supply FROM token_metas WHERE is_erc20 = 1 AND decimals = 6;"}, {"role": "user", "content": "Now, join with token_prices_latest to also include the latest price for each token."}, {"role": "assistant", "content": "SELECT tm.symbol, tm.contract_address, tm.name, tm.total_supply, tpl.price AS latest_price\nFROM token_metas tm\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nWHERE tm.is_erc20 = 1 AND tm.decimals = 6;"}, {"role": "user", "content": "Only include tokens where the latest price is between 0.5 and 2.0 USD, and limit the result to the top 5 tokens by price descending."}, {"role": "assistant", "content": "SELECT tm.symbol, tm.contract_address, tm.name, tm.total_supply, tpl.price AS latest_price\nFROM token_metas tm\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nWHERE tm.is_erc20 = 1 AND tm.decimals = 6 AND tpl.price BETWEEN 0.5 AND 2.0\nORDER BY tpl.price DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\n", "conversations": [{"role": "user", "content": "Find the date (calendar day) with the highest total number of game sessions. Show the date and the total session count."}, {"role": "assistant", "content": "SELECT CAST(start_time AS DATE) AS session_date, COUNT(*) AS total_sessions\nFROM gaming_technology.game_sessions\nGROUP BY session_date\nORDER BY total_sessions DESC\nLIMIT 1;"}, {"role": "user", "content": "Also include the day with the second highest session count."}, {"role": "assistant", "content": "SELECT session_date, total_sessions FROM (\n SELECT CAST(start_time AS DATE) AS session_date, COUNT(*) AS total_sessions,\n ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn\n FROM gaming_technology.game_sessions\n GROUP BY session_date\n) ranked\nWHERE rn <= 2\nORDER BY total_sessions DESC;"}, {"role": "user", "content": "Can you also add the total score across all sessions for each of those days?"}, {"role": "assistant", "content": "SELECT session_date, total_sessions, total_score FROM (\n SELECT CAST(start_time AS DATE) AS session_date,\n COUNT(*) AS total_sessions,\n SUM(score) AS total_score,\n ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn\n FROM gaming_technology.game_sessions\n GROUP BY session_date\n) ranked\nWHERE rn <= 2\nORDER BY total_sessions DESC;"}, {"role": "user", "content": "I got an error that session_date is not found, can you fix this SQL?"}, {"role": "assistant", "content": "SELECT sub.session_date, sub.total_sessions, sub.total_score FROM (\n SELECT CAST(start_time AS DATE) AS session_date,\n COUNT(*) AS total_sessions,\n SUM(score) AS total_score,\n ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn\n FROM gaming_technology.game_sessions\n GROUP BY CAST(start_time AS DATE)\n) AS sub\nWHERE sub.rn <= 2\nORDER BY sub.total_sessions DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n", "conversations": [{"role": "user", "content": "Give me each server's name, the region, and the maximum number of players that have been connected at once."}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, MAX(s.current_players) AS max_players_seen\nFROM gaming_technology.servers s\nGROUP BY s.server_id, s.server_name, s.region;"}, {"role": "user", "content": "Could you also include the associated game title for each server?"}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, g.title AS game_title, MAX(s.current_players) AS max_players_seen\nFROM gaming_technology.servers s\nJOIN gaming_technology.games g ON s.game_id = g.game_id\nGROUP BY s.server_id, s.server_name, s.region, g.title;"}, {"role": "user", "content": "Now, can you show only servers where the max number of players ever connected exceeded 20?"}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, g.title AS game_title, MAX(s.current_players) AS max_players_seen\nFROM gaming_technology.servers s\nJOIN gaming_technology.games g ON s.game_id = g.game_id\nGROUP BY s.server_id, s.server_name, s.region, g.title\nHAVING MAX(s.current_players) > 20;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id.uuid, username.text, email.text, password_hash.text, registration_date.timestamptz, last_login.timestamptz, country_code.text, status.text, profile_data.jsonb )\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\nCREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\nCREATE TABLE gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n", "conversations": [{"role": "user", "content": "List the usernames and registration dates for all players from 'Canada'."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE country_code = 'Canada';"}, {"role": "user", "content": "Now, only show players from Canada who registered after January 1st, 2023."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE country_code = 'Canada' AND registration_date > '2023-01-01';"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_id) )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n", "conversations": [{"role": "user", "content": "Retrieve the title and release_date of all games on the 'PC' platform."}, {"role": "assistant", "content": "SELECT title, release_date\nFROM gaming_technology.games\nWHERE platform = 'PC';"}, {"role": "user", "content": "Now exclude any games released before 2018."}, {"role": "assistant", "content": "SELECT title, release_date\nFROM gaming_technology.games\nWHERE platform = 'PC'\n AND release_date >= '2018-01-01';"}, {"role": "user", "content": "Also sort the results by release_date in ascending order."}, {"role": "assistant", "content": "SELECT title, release_date\nFROM gaming_technology.games\nWHERE platform = 'PC'\n AND release_date >= '2018-01-01'\nORDER BY release_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, property_id text, reservation_id text, guest_id text, rating_overall int, rating_cleanliness int, rating_service int, rating_location int, rating_value int, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "List each property and the number of public reviews it has received."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, COUNT(r.review_id) AS public_review_count\nFROM hospitality_technology.properties p\nLEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id AND r.is_public = TRUE\nGROUP BY p.property_id, p.property_name;"}, {"role": "user", "content": "I only want properties which have received at least 10 public reviews."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, COUNT(r.review_id) AS public_review_count\nFROM hospitality_technology.properties p\nLEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id AND r.is_public = TRUE\nGROUP BY p.property_id, p.property_name\nHAVING COUNT(r.review_id) >= 10;"}, {"role": "user", "content": "Additionally, please provide the average overall rating for each of these properties."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, COUNT(r.review_id) AS public_review_count, AVG(r.rating_overall) AS avg_public_rating\nFROM hospitality_technology.properties p\nLEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id AND r.is_public = TRUE\nGROUP BY p.property_id, p.property_name\nHAVING COUNT(r.review_id) >= 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "List the username, registration date, and the creation date of the first wallet created by each user who owns at least one wallet."}, {"role": "assistant", "content": "SELECT u.username, u.created_at AS registration_date, MIN(w.created_at) AS first_wallet_creation_date FROM web3.users AS u JOIN web3.wallets AS w ON u.user_id = w.user_id GROUP BY u.user_id, u.username, u.created_at;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\n", "conversations": [{"role": "user", "content": "Show the top 5 transactions with the highest number of token transfers, along with their Ethereum value. Include transaction_id, token_transfer_count, and ether_value."}, {"role": "assistant", "content": "SELECT\n tt.transaction_id,\n COUNT(tt.transfer_id) AS token_transfer_count,\n t.value AS ether_value\nFROM web3.token_transfers tt\nJOIN web3.transactions t\n ON tt.transaction_id = t.transaction_id\nGROUP BY\n tt.transaction_id,\n t.value\nORDER BY token_transfer_count DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.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.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all maintenance logs for vehicles acquired in the year 2023. Include log ID, vehicle make, model, service date, and cost."}, {"role": "assistant", "content": "SELECT ml.log_id, v.make, v.model, ml.service_date, ml.cost FROM transportation.maintenance_logs AS ml JOIN transportation.vehicles AS v ON ml.vehicle_id = v.vehicle_id WHERE EXTRACT(YEAR FROM v.acquisition_date) = 2023;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts (\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 (\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.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\nCREATE TABLE web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "Show each contract's address along with the total number of events it has emitted and the total number of transactions sent to it."}, {"role": "assistant", "content": "SELECT\n c.address,\n COUNT(e.event_id) AS event_count,\n COUNT(t.transaction_id) AS tx_count\nFROM web3.contracts c\nLEFT JOIN web3.events e\n ON c.contract_id = e.contract_id\nLEFT JOIN web3.transactions t\n ON c.address = t.to_address\nGROUP BY c.address;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text, tag_name text, created_at timestamp )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the conversation ID and creation time for group chats that have received at least one message."}, {"role": "assistant", "content": "SELECT DISTINCT T1.conversation_id, T1.created_at FROM social_media.conversations AS T1 INNER JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE;"}, {"role": "user", "content": "Only show those created in 2024."}, {"role": "assistant", "content": "SELECT DISTINCT T1.conversation_id, T1.created_at FROM social_media.conversations AS T1 INNER JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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 name and job title of employees whose job title includes 'Manager' and who do not have a listed manager."}, {"role": "assistant", "content": "SELECT first_name, last_name, job_title FROM government_services.employees WHERE job_title LIKE '%Manager%' AND manager_employee_id IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n", "conversations": [{"role": "user", "content": "List the top 5 tokens by total USD inflow and outflow, including net flow, sorted by net flow descending."}, {"role": "assistant", "content": "WITH inflow AS (\n SELECT token_symbol, chain, SUM(usd_value) AS usd_in\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY token_symbol, chain\n),\noutflow AS (\n SELECT token_symbol, chain, SUM(usd_value) AS usd_out\n FROM smart_money_token_inflow\n WHERE type = 2\n GROUP BY token_symbol, chain\n),\nnet_flow AS (\n SELECT\n i.token_symbol,\n i.chain,\n COALESCE(i.usd_in, 0) AS usd_in,\n COALESCE(o.usd_out, 0) AS usd_out,\n COALESCE(i.usd_in, 0) - COALESCE(o.usd_out, 0) AS net_flow\n FROM inflow i\n LEFT JOIN outflow o\n ON i.token_symbol = o.token_symbol\n AND i.chain = o.chain\n)\nSELECT token_symbol, chain, usd_in, usd_out, net_flow\nFROM net_flow\nORDER BY net_flow DESC\nLIMIT 5;"}, {"role": "user", "content": "Now filter the results to only include tokens where net flow is positive."}, {"role": "assistant", "content": "WITH inflow AS (\n SELECT token_symbol, chain, SUM(usd_value) AS usd_in\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY token_symbol, chain\n),\noutflow AS (\n SELECT token_symbol, chain, SUM(usd_value) AS usd_out\n FROM smart_money_token_inflow\n WHERE type = 2\n GROUP BY token_symbol, chain\n),\nnet_flow AS (\n SELECT\n i.token_symbol,\n i.chain,\n COALESCE(i.usd_in, 0) AS usd_in,\n COALESCE(o.usd_out, 0) AS usd_out,\n COALESCE(i.usd_in, 0) - COALESCE(o.usd_out, 0) AS net_flow\n FROM inflow i\n LEFT JOIN outflow o\n ON i.token_symbol = o.token_symbol\n AND i.chain = o.chain\n)\nSELECT token_symbol, chain, usd_in, usd_out, net_flow\nFROM net_flow\nWHERE net_flow > 0\nORDER BY net_flow DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.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": "Retrieve all notifications with status 'failed' along with the citizen's full name and contact_phone for those notifications that occurred in the past 30 days."}, {"role": "assistant", "content": "SELECT n.notification_id,\n n.sent_at,\n n.status,\n c.first_name || ' ' || c.last_name AS full_name,\n c.contact_phone\nFROM government_services.notifications n\nJOIN government_services.citizens c\n ON n.citizen_id = c.citizen_id\nWHERE n.status = 'failed'\n AND n.sent_at >= NOW() - INTERVAL '30 days';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\nCREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n", "conversations": [{"role": "user", "content": "Show each passenger's first_name, last_name, and the total number of bookings they have made."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id, p.first_name, p.last_name;"}, {"role": "user", "content": "Filter to only include passengers who have made more than 3 bookings."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id, p.first_name, p.last_name\nHAVING COUNT(b.booking_id) > 3;"}, {"role": "user", "content": "Also include the average fare for these passengers and order by booking_count descending."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id, p.first_name, p.last_name\nHAVING COUNT(b.booking_id) > 3\nORDER BY booking_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "For each passenger, compute the count of bookings and average fare for bookings made in February 2024."}, {"role": "assistant", "content": "SELECT p.passenger_id, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.booking_time >= '2024-02-01' AND b.booking_time < '2024-03-01'\nGROUP BY p.passenger_id;"}, {"role": "user", "content": "I need to see the passengers' first and last names instead of IDs and only include those with an average fare greater than 75."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.booking_time >= '2024-02-01' AND b.booking_time < '2024-03-01'\nGROUP BY p.first_name, p.last_name\nHAVING AVG(b.fare) > 75;"}, {"role": "user", "content": "Also, order the results by booking_count descending and limit the output to the top 5 passengers."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare\nFROM transportation.passengers p\nJOIN transportation.bookings b ON p.passenger_id = b.passenger_id\nWHERE b.booking_time >= '2024-02-01' AND b.booking_time < '2024-03-01'\nGROUP BY p.first_name, p.last_name\nHAVING AVG(b.fare) > 75\nORDER BY booking_count DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "I want a report of public posts with images in the last 30 days that shows post_id, content, author's username and email, and the count of likes, ordered by like count descending, limit to top 5."}, {"role": "assistant", "content": "SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 5;"}, {"role": "user", "content": "Actually, only include posts created by verified users."}, {"role": "assistant", "content": "SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' AND u.is_verified = true GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 5;"}, {"role": "user", "content": "Also, filter to posts within 50 kilometers of latitude 40.0 and longitude -74.0."}, {"role": "assistant", "content": "SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' AND u.is_verified = true AND p.location_lat BETWEEN 40.0 - 0.45 AND 40.0 + 0.45 AND p.location_lon BETWEEN -74.0 - 0.45 AND -74.0 + 0.45 GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 5;"}, {"role": "user", "content": "Finally, reduce the limit to top 3 posts only."}, {"role": "assistant", "content": "SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' AND u.is_verified = true AND p.location_lat BETWEEN 40.0 - 0.45 AND 40.0 + 0.45 AND p.location_lon BETWEEN -74.0 - 0.45 AND -74.0 + 0.45 GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )\n", "conversations": [{"role": "user", "content": "For each account type and status, can you show the total number of accounts and their combined balance per currency?"}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance\nFROM financial_services.accounts\nGROUP BY account_type, status, currency;"}, {"role": "user", "content": "Can you add the average interest rate for each group in the result?"}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, status, currency;"}, {"role": "user", "content": "Please filter the results to only include groups where the total_balance is above 50000."}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, status, currency\nHAVING SUM(balance) > 50000;"}, {"role": "user", "content": "Finally, sort the result by average_interest_rate in descending order."}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, status, currency\nHAVING SUM(balance) > 50000\nORDER BY average_interest_rate DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "List all services, showing the service name, category, and the name of the property where it is offered."}, {"role": "assistant", "content": "SELECT T1.service_name, T1.category, T2.property_name FROM hospitality_technology.services AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id;"}, {"role": "user", "content": "Please filter the results to only include services that are currently available."}, {"role": "assistant", "content": "SELECT T1.service_name, T1.category, T2.property_name FROM hospitality_technology.services AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.is_available = TRUE;"}, {"role": "user", "content": "Can you also include the star rating of the property and order the results by property star rating descending?"}, {"role": "assistant", "content": "SELECT T1.service_name, T1.category, T2.property_name, T2.star_rating FROM hospitality_technology.services AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.is_available = TRUE ORDER BY T2.star_rating DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\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": "List all tokens on the 'BSC' chain with a trend rank between 6 and 20 (inclusive), along with their symbol, price, and liquidity."}, {"role": "assistant", "content": "SELECT t.token_symbol, t.price, d.liquidity\nFROM token_basic_info t\nJOIN token_dexpool_info d ON lower(t.token_symbol) = lower(d.token_symbol) AND t.chain = d.chain\nWHERE t.chain = 'BSC' AND t.trend_rank BETWEEN 6 AND 20;"}, {"role": "user", "content": "Could you also show their 24-hour trading volume and only include tokens with a positive 24-hour price change percentage?"}, {"role": "assistant", "content": "SELECT t.token_symbol, t.price, d.liquidity, d.volume_24h\nFROM token_basic_info t\nJOIN token_dexpool_info d ON lower(t.token_symbol) = lower(d.token_symbol) AND t.chain = d.chain\nWHERE t.chain = 'BSC' AND t.trend_rank BETWEEN 6 AND 20 AND t.price_change_percentage_24h > 0;"}, {"role": "user", "content": "Add the narrative for each token and order the results by liquidity descending, showing only the top 5."}, {"role": "assistant", "content": "SELECT t.token_symbol, t.price, d.liquidity, d.volume_24h, t.narrative\nFROM token_basic_info t\nJOIN token_dexpool_info d ON lower(t.token_symbol) = lower(d.token_symbol) AND t.chain = d.chain\nWHERE t.chain = 'BSC' AND t.trend_rank BETWEEN 6 AND 20 AND t.price_change_percentage_24h > 0\nORDER BY d.liquidity DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\n", "conversations": [{"role": "user", "content": "Show all claims handled by agents who have uploaded at least one claim document. Include the claim_id, agent's uploaded document_id, and the incident date."}, {"role": "assistant", "content": "SELECT c.claim_id, cd.document_id, c.incident_date\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_handler_id = cd.uploaded_by\nWHERE cd.claim_id = c.claim_id;"}, {"role": "user", "content": "Can you also include the file_name and the uploaded timestamp of each document?"}, {"role": "assistant", "content": "SELECT c.claim_id, cd.document_id, c.incident_date, cd.file_name, cd.uploaded_at\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_handler_id = cd.uploaded_by\nWHERE cd.claim_id = c.claim_id;"}, {"role": "user", "content": "Actually, only show records where the claim status is 'Open' and the document is of type 'POLICE_REPORT'."}, {"role": "assistant", "content": "SELECT c.claim_id, cd.document_id, c.incident_date, cd.file_name, cd.uploaded_at\nFROM insurance.claims c\nJOIN insurance.claim_documents cd ON c.claim_handler_id = cd.uploaded_by\nWHERE cd.claim_id = c.claim_id\n AND c.status = 'Open'\n AND cd.document_type = 'POLICE_REPORT';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.notifications ( notification_id text, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "How many comments were created in the month of March 2024?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.comments WHERE created_at >= '2024-03-01' AND created_at < '2024-04-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\n", "conversations": [{"role": "user", "content": "List the usernames and status of all players who have 'de' as their country_code."}, {"role": "assistant", "content": "SELECT username, status FROM gaming_technology.players WHERE country_code = 'DE';"}, {"role": "user", "content": "Can you also add their registration_date and last_login fields?"}, {"role": "assistant", "content": "SELECT username, status, registration_date, last_login FROM gaming_technology.players WHERE country_code = 'DE';"}, {"role": "user", "content": "Now, only include players whose status is 'inactive'."}, {"role": "assistant", "content": "SELECT username, status, registration_date, last_login FROM gaming_technology.players WHERE country_code = 'DE' AND status = 'inactive';"}, {"role": "user", "content": "Sort the results by last_login descending, showing players who logged in most recently first."}, {"role": "assistant", "content": "SELECT username, status, registration_date, last_login FROM gaming_technology.players WHERE country_code = 'DE' AND status = 'inactive' ORDER BY last_login 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 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 )\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": "What is the average ROI for smart money addresses on the Ethereum chain?"}, {"role": "assistant", "content": "SELECT AVG(roi) FROM smart_money_token_performance WHERE chain = 'Ethereum';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.transactions ( transaction_id.text, block_id.text, sender_address.text, receiver_address.text, amount.numeric, timestamp.timestamp, signature.text )\nCREATE TABLE blockchain.addresses ( address_id.text, public_key.text, balance.numeric )\nCREATE TABLE blockchain.nodes (\n node_id character varying(64) NOT NULL, -- unique identifier for the node\n ip_address character varying(15) NOT NULL, -- IP address of the node\n port integer NOT NULL, -- port number of the node\n last_seen timestamp NOT NULL, -- last time the node was active\n PRIMARY KEY (node_id)\n)\n", "conversations": [{"role": "user", "content": "Show me each transaction ID along with the sender's public key, the receiver's balance, and the transaction amount."}, {"role": "assistant", "content": "SELECT t.transaction_id, a_sender.public_key AS sender_public_key, a_receiver.balance AS receiver_balance, t.amount\nFROM blockchain.transactions t\nJOIN blockchain.addresses a_sender ON t.sender_address = a_sender.address_id\nJOIN blockchain.addresses a_receiver ON t.receiver_address = a_receiver.address_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens (\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.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 ( 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, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Find the total number of documents uploaded by each citizen along with their first and last names."}, {"role": "assistant", "content": "SELECT c.citizen_id, c.first_name, c.last_name, COUNT(d.document_id) AS document_count\nFROM government_services.citizens c\nLEFT JOIN government_services.documents d ON c.citizen_id = d.citizen_id\nGROUP BY c.citizen_id, c.first_name, c.last_name;"}, {"role": "user", "content": "Actually, I only want to include those citizens who have uploaded documents in the last 30 days."}, {"role": "assistant", "content": "SELECT c.citizen_id, c.first_name, c.last_name, COUNT(d.document_id) AS document_count\nFROM government_services.citizens c\nJOIN government_services.documents d ON c.citizen_id = d.citizen_id\nWHERE d.upload_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY c.citizen_id, c.first_name, c.last_name;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id.text, user_id.text, theme.text, email_notifications_enabled.boolean, push_notifications_enabled.boolean, private_profile.boolean, updated_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all unread notifications received by users who have a private profile, showing all notification details."}, {"role": "assistant", "content": "SELECT n.* FROM social_media.notifications n JOIN social_media.user_settings s ON n.recipient_user_id = s.user_id WHERE n.read_at IS NULL AND s.private_profile = TRUE;"}, {"role": "user", "content": "Actually, only include notifications of type 'like'."}, {"role": "assistant", "content": "SELECT n.* FROM social_media.notifications n JOIN social_media.user_settings s ON n.recipient_user_id = s.user_id WHERE n.read_at IS NULL AND s.private_profile = TRUE AND n.notification_type = 'like';"}, {"role": "user", "content": "Order them by creation time, most recent first."}, {"role": "assistant", "content": "SELECT n.* FROM social_media.notifications n JOIN social_media.user_settings s ON n.recipient_user_id = s.user_id WHERE n.read_at IS NULL AND s.private_profile = TRUE AND n.notification_type = 'like' ORDER BY n.created_at DESC;"}, {"role": "user", "content": "And limit the results to the top 10."}, {"role": "assistant", "content": "SELECT n.* FROM social_media.notifications n JOIN social_media.user_settings s ON n.recipient_user_id = s.user_id WHERE n.read_at IS NULL AND s.private_profile = TRUE AND n.notification_type = 'like' ORDER BY n.created_at DESC LIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "For each security, find any other security within the same sector that has a later last_updated timestamp. Return a.ticker_symbol, b.ticker_symbol, and b.last_updated."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, b.ticker_symbol AS symbol_b, b.last_updated AS later_update FROM financial_services.securities a JOIN financial_services.securities b ON a.sector = b.sector AND b.last_updated > a.last_updated AND a.security_id <> b.security_id;"}, {"role": "user", "content": "Exclude cases where b.last_updated is more than 30 days after a.last_updated."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, b.ticker_symbol AS symbol_b, b.last_updated AS later_update FROM financial_services.securities a JOIN financial_services.securities b ON a.sector = b.sector AND b.last_updated > a.last_updated AND a.security_id <> b.security_id AND b.last_updated <= a.last_updated + INTERVAL '30 days';"}, {"role": "user", "content": "Sort the result by symbol_a then by later_update in descending order."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, b.ticker_symbol AS symbol_b, b.last_updated AS later_update FROM financial_services.securities a JOIN financial_services.securities b ON a.sector = b.sector AND b.last_updated > a.last_updated AND a.security_id <> b.security_id AND b.last_updated <= a.last_updated + INTERVAL '30 days' ORDER BY a.ticker_symbol ASC, later_update DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )\nCREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, bar_number character varying(64) UNIQUE NOT NULL, firm_id character varying(64), email character varying(128) UNIQUE NOT NULL, phone character varying(32), specialization text, hire_date timestamp NOT NULL, is_partner boolean DEFAULT false, PRIMARY KEY (lawyer_id) )\nCREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\n", "conversations": [{"role": "user", "content": "Show me the first and last names of clients along with the first and last names of their lead lawyers for all open cases."}, {"role": "assistant", "content": "SELECT c.first_name AS client_first, c.last_name AS client_last, l.first_name AS lawyer_first, l.last_name AS lawyer_last\nFROM legal_services.cases cs\nJOIN legal_services.clients c ON cs.client_id = c.client_id\nJOIN legal_services.lawyers l ON cs.lead_lawyer_id = l.lawyer_id\nWHERE cs.status = 'Open';"}, {"role": "user", "content": "Actually, only include cases in the 'Civil Court' jurisdiction."}, {"role": "assistant", "content": "SELECT c.first_name AS client_first, c.last_name AS client_last, l.first_name AS lawyer_first, l.last_name AS lawyer_last\nFROM legal_services.cases cs\nJOIN legal_services.clients c ON cs.client_id = c.client_id\nJOIN legal_services.lawyers l ON cs.lead_lawyer_id = l.lawyer_id\nWHERE cs.status = 'Open'\n AND cs.court_jurisdiction = 'Civil Court';"}, {"role": "user", "content": "And order the results by client_last ascending."}, {"role": "assistant", "content": "SELECT c.first_name AS client_first, c.last_name AS client_last, l.first_name AS lawyer_first, l.last_name AS lawyer_last\nFROM legal_services.cases cs\nJOIN legal_services.clients c ON cs.client_id = c.client_id\nJOIN legal_services.lawyers l ON cs.lead_lawyer_id = l.lawyer_id\nWHERE cs.status = 'Open'\n AND cs.court_jurisdiction = 'Civil Court'\nORDER BY c.last_name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 )\n", "conversations": [{"role": "user", "content": "Show the number of trips operated by each driver along with the earliest and latest scheduled departure dates for them."}, {"role": "assistant", "content": "SELECT driver_id, COUNT(*) AS trip_count, MIN(scheduled_departure) AS first_departure, MAX(scheduled_departure) AS last_departure FROM transportation.trips GROUP BY driver_id;"}, {"role": "user", "content": "Can you limit this to only include drivers who have operated more than 5 trips?"}, {"role": "assistant", "content": "SELECT driver_id, COUNT(*) AS trip_count, MIN(scheduled_departure) AS first_departure, MAX(scheduled_departure) AS last_departure FROM transportation.trips GROUP BY driver_id HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Add the total number of passengers transported by each driver."}, {"role": "assistant", "content": "SELECT driver_id, COUNT(*) AS trip_count, SUM(passenger_count) AS total_passengers, MIN(scheduled_departure) AS first_departure, MAX(scheduled_departure) AS last_departure FROM transportation.trips GROUP BY driver_id HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Also, sort the result by total_passengers in descending order."}, {"role": "assistant", "content": "SELECT driver_id, COUNT(*) AS trip_count, SUM(passenger_count) AS total_passengers, MIN(scheduled_departure) AS first_departure, MAX(scheduled_departure) AS last_departure FROM transportation.trips GROUP BY driver_id HAVING COUNT(*) > 5 ORDER BY total_passengers DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.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 )\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": "Provide a list of order_id and notification_id for all orders and notifications that occurred on the same day for each user."}, {"role": "assistant", "content": "SELECT o.order_id,\n n.notification_id\nFROM trading_platform.orders o\nJOIN trading_platform.notifications n\n ON o.user_id = n.user_id\n AND DATE(o.created_at) = DATE(n.sent_at);"}, {"role": "user", "content": "Now refine it to include only notifications that have been read and orders with status 'completed'."}, {"role": "assistant", "content": "SELECT o.order_id,\n n.notification_id\nFROM trading_platform.orders o\nJOIN trading_platform.notifications n\n ON o.user_id = n.user_id\n AND DATE(o.created_at) = DATE(n.sent_at)\nWHERE o.status = 'completed'\n AND n.read_at IS NOT NULL;"}, {"role": "user", "content": "Include the order's quantity and notification message in the result, and sort by n.read_at descending."}, {"role": "assistant", "content": "SELECT o.order_id,\n o.quantity,\n n.notification_id,\n n.message,\n n.read_at\nFROM trading_platform.orders o\nJOIN trading_platform.notifications n\n ON o.user_id = n.user_id\n AND DATE(o.created_at) = DATE(n.sent_at)\nWHERE o.status = 'completed'\n AND n.read_at IS NOT NULL\nORDER BY n.read_at DESC;"}, {"role": "user", "content": "Limit the output to the top 5 records."}, {"role": "assistant", "content": "SELECT o.order_id,\n o.quantity,\n n.notification_id,\n n.message,\n n.read_at\nFROM trading_platform.orders o\nJOIN trading_platform.notifications n\n ON o.user_id = n.user_id\n AND DATE(o.created_at) = DATE(n.sent_at)\nWHERE o.status = 'completed'\n AND n.read_at IS NOT NULL\nORDER BY n.read_at DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_token_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": "Find projects from project_fundraising_record that had fundraising rounds in the year 2023 and have a corresponding token in token_dexpool_info. Show the project name, the investment value, the fundraising round name, and the token symbol and current price from the DEX pool table. Use a flexible match condition where the project name contains the token symbol or vice versa (case-insensitive)."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.investment_value, pfr.rounds_name, tdi.token_symbol, tdi.price FROM project_fundraising_record AS pfr JOIN token_dexpool_info AS tdi ON LOWER(pfr.project_name) LIKE '%' || LOWER(tdi.token_symbol) || '%' OR LOWER(tdi.token_symbol) LIKE '%' || LOWER(pfr.project_name) || '%' WHERE pfr.investment_date LIKE '2023%';"}, {"role": "user", "content": "The fuzzy match seems okay, but I want to refine the results further. Only show the results for tokens found on the 'Ethereum' chain."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.investment_value, pfr.rounds_name, tdi.token_symbol, tdi.price FROM project_fundraising_record AS pfr JOIN token_dexpool_info AS tdi ON LOWER(pfr.project_name) LIKE '%' || LOWER(tdi.token_symbol) || '%' OR LOWER(tdi.token_symbol) LIKE '%' || LOWER(pfr.project_name) || '%' WHERE pfr.investment_date LIKE '2023%' AND tdi.chain = 'Ethereum';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id.text, property_id.text, first_name.text, last_name.text, position.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, is_active.boolean, access_level.integer, manager_id.text, created_at.timestamp )\nCREATE TABLE hospitality_technology.services ( service_id.text, property_id.text, service_name.text, description.text, category.text, price.numeric, unit.text, is_available.boolean, department.text )\nCREATE TABLE hospitality_technology.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": "How many available rooms and available services are there for each property?"}, {"role": "assistant", "content": "SELECT\n r.property_id,\n SUM(CASE WHEN r.status = 'Available' THEN 1 ELSE 0 END) AS available_rooms_count,\n SUM(CASE WHEN s.is_available = TRUE THEN 1 ELSE 0 END) AS available_services_count\nFROM hospitality_technology.rooms AS r\nLEFT JOIN hospitality_technology.services AS s\n ON r.property_id = s.property_id\nGROUP BY r.property_id;"}, {"role": "user", "content": "Exclude properties that have fewer than 10 available rooms."}, {"role": "assistant", "content": "SELECT\n r.property_id,\n SUM(CASE WHEN r.status = 'Available' THEN 1 ELSE 0 END) AS available_rooms_count,\n SUM(CASE WHEN s.is_available = TRUE THEN 1 ELSE 0 END) AS available_services_count\nFROM hospitality_technology.rooms AS r\nLEFT JOIN hospitality_technology.services AS s\n ON r.property_id = s.property_id\nGROUP BY r.property_id\nHAVING SUM(CASE WHEN r.status = 'Available' THEN 1 ELSE 0 END) >= 10;"}, {"role": "user", "content": "Also order the results by available_services_count descending."}, {"role": "assistant", "content": "SELECT\n r.property_id,\n SUM(CASE WHEN r.status = 'Available' THEN 1 ELSE 0 END) AS available_rooms_count,\n SUM(CASE WHEN s.is_available = TRUE THEN 1 ELSE 0 END) AS available_services_count\nFROM hospitality_technology.rooms AS r\nLEFT JOIN hospitality_technology.services AS s\n ON r.property_id = s.property_id\nGROUP BY r.property_id\nHAVING SUM(CASE WHEN r.status = 'Available' THEN 1 ELSE 0 END) >= 10\nORDER BY available_services_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all active products with a base premium exceeding 1500 that were created after January 1, 2023, including their product name, type, and base premium. Order the results by creation date ascending."}, {"role": "assistant", "content": "SELECT product_name, product_type, base_premium FROM insurance.insurance_products WHERE is_active = TRUE AND base_premium > 1500 AND created_at >= '2023-01-01' ORDER BY created_at ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer )\n", "conversations": [{"role": "user", "content": "Find all blocks where the difficulty is between 1000 and 2000."}, {"role": "assistant", "content": "SELECT * FROM blockchain.blocks WHERE difficulty BETWEEN 1000 AND 2000;"}, {"role": "user", "content": "Now filter these results to only show blocks mined after June 1, 2023."}, {"role": "assistant", "content": "SELECT * FROM blockchain.blocks WHERE difficulty BETWEEN 1000 AND 2000 AND timestamp > '2023-06-01';"}, {"role": "user", "content": "Actually, I want to see the count of such blocks grouped by month in 2023."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count\nFROM blockchain.blocks\nWHERE difficulty BETWEEN 1000 AND 2000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31'\nGROUP BY month\nORDER BY month;"}, {"role": "user", "content": "Can you also include the average difficulty for each month in the results?"}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count, AVG(difficulty) AS avg_difficulty\nFROM blockchain.blocks\nWHERE difficulty BETWEEN 1000 AND 2000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31'\nGROUP BY month\nORDER BY month;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "Show the agency names and the number of active services they currently offer. List only those agencies with more than 2 active services."}, {"role": "assistant", "content": "SELECT a.agency_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.agencies a\nJOIN government_services.services s ON a.agency_id = s.agency_id\nWHERE s.is_active = TRUE\nGROUP BY a.agency_name\nHAVING COUNT(s.service_id) > 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\n", "conversations": [{"role": "user", "content": "List all pairs of citizens who registered on the same date. Include each citizen's full name and the shared registration date."}, {"role": "assistant", "content": "SELECT c1.first_name || ' ' || c1.last_name AS full_name_1,\n c2.first_name || ' ' || c2.last_name AS full_name_2,\n DATE(c1.registration_date) AS registration_date\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON DATE(c1.registration_date) = DATE(c2.registration_date)\n AND c1.citizen_id < c2.citizen_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 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 varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE 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 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_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(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 )\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 NFT collections deployed after block number 10000000 with more than 500 tokens, showing contract_address, name, and token_count."}, {"role": "assistant", "content": "SELECT contract_address, name, token_count\nFROM nft_collections\nWHERE deploy_block_number > 10000000\n AND token_count > 500;"}, {"role": "user", "content": "Join with nft_metadata to calculate the average rarity_score per collection."}, {"role": "assistant", "content": "SELECT nc.contract_address,\n nc.name,\n nc.token_count,\n AVG(nm.rarity_score) AS avg_rarity\nFROM nft_collections nc\nLEFT JOIN nft_metadata nm\n ON nc.contract_address = nm.contract_address\nWHERE nc.deploy_block_number > 10000000\n AND nc.token_count > 500\nGROUP BY nc.contract_address, nc.name, nc.token_count;"}, {"role": "user", "content": "Filter collections with average rarity_score above 80 and include floor_price."}, {"role": "assistant", "content": "SELECT nc.contract_address,\n nc.name,\n nc.token_count,\n AVG(nm.rarity_score) AS avg_rarity,\n nc.floor_price\nFROM nft_collections nc\nLEFT JOIN nft_metadata nm\n ON nc.contract_address = nm.contract_address\nWHERE nc.deploy_block_number > 10000000\n AND nc.token_count > 500\nGROUP BY nc.contract_address, nc.name, nc.token_count, nc.floor_price\nHAVING AVG(nm.rarity_score) > 80;"}, {"role": "user", "content": "Order the results by floor_price descending and limit to the top 5 collections."}, {"role": "assistant", "content": "SELECT nc.contract_address,\n nc.name,\n nc.token_count,\n AVG(nm.rarity_score) AS avg_rarity,\n nc.floor_price\nFROM nft_collections nc\nLEFT JOIN nft_metadata nm\n ON nc.contract_address = nm.contract_address\nWHERE nc.deploy_block_number > 10000000\n AND nc.token_count > 500\nGROUP BY nc.contract_address, nc.name, nc.token_count, nc.floor_price\nHAVING AVG(nm.rarity_score) > 80\nORDER BY CAST(nc.floor_price AS numeric) DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each user, show the date of their earliest and latest wallet creation."}, {"role": "assistant", "content": "SELECT user_id,\n MIN(created_at) AS first_created,\n MAX(created_at) AS last_created\nFROM web3.wallets\nGROUP BY user_id;"}, {"role": "user", "content": "Actually, also include the count of wallets each user has created."}, {"role": "assistant", "content": "SELECT user_id,\n MIN(created_at) AS first_created,\n MAX(created_at) AS last_created,\n COUNT(*) AS wallet_count\nFROM web3.wallets\nGROUP BY user_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.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": "Which routes have their origin and destination in the same city? Show the route number, description, and the origin and destination location IDs."}, {"role": "assistant", "content": "SELECT r.route_number, r.description, r.origin_location_id, r.destination_location_id\nFROM transportation.routes r\nJOIN transportation.routes r2 ON r.origin_location_id = r2.destination_location_id AND r.route_id = r2.route_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find all pairs of users who registered at exactly the same timestamp, showing both user IDs, usernames, and the shared registration timestamp."}, {"role": "assistant", "content": "SELECT u1.user_id AS user_id_1, u1.username AS username_1, u2.user_id AS user_id_2, u2.username AS username_2, u1.created_at\nFROM web3.users u1\nJOIN web3.users u2\n ON u1.created_at = u2.created_at\n AND u1.user_id < u2.user_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\n", "conversations": [{"role": "user", "content": "Find token transfers within the same transaction where the recipient of an earlier transfer (based on log_index) becomes the sender of a later transfer. List the transaction ID, the earlier transfer ID, the later transfer ID, the shared address, and the value transferred in both cases."}, {"role": "assistant", "content": "SELECT t1.transaction_id, t1.transfer_id AS earlier_transfer_id, t2.transfer_id AS later_transfer_id, t1.to_address AS shared_address, t1.value AS earlier_transfer_value, t2.value AS later_transfer_value FROM web3.token_transfers AS t1 JOIN web3.token_transfers AS t2 ON t1.transaction_id = t2.transaction_id WHERE t1.to_address = t2.from_address AND t1.log_index < t2.log_index;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "List the document ID, file name, document type, and upload date for all documents."}, {"role": "assistant", "content": "SELECT document_id, file_name, document_type, uploaded_at FROM insurance.claim_documents;"}, {"role": "user", "content": "From these results, only show documents of type 'Insurance Application'."}, {"role": "assistant", "content": "SELECT document_id, file_name, document_type, uploaded_at FROM insurance.claim_documents WHERE document_type = 'Insurance Application';"}, {"role": "user", "content": "Also, only include files larger than 1 megabyte."}, {"role": "assistant", "content": "SELECT document_id, file_name, document_type, uploaded_at FROM insurance.claim_documents WHERE document_type = 'Insurance Application' AND file_size_bytes > 1048576;"}, {"role": "user", "content": "Okay, now just show the document ID, file name, and file size, ordered by file size descending."}, {"role": "assistant", "content": "SELECT document_id, file_name, file_size_bytes FROM insurance.claim_documents WHERE document_type = 'Insurance Application' AND file_size_bytes > 1048576 ORDER BY file_size_bytes DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n", "conversations": [{"role": "user", "content": "Show me the list of all room numbers and their corresponding guest full names for current reservations (status is 'Occupied' or 'CheckedIn')."}, {"role": "assistant", "content": "SELECT r.room_number, g.first_name || ' ' || g.last_name AS guest_full_name\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.rooms r ON res.room_id = r.room_id\nJOIN hospitality_technology.guests g ON res.guest_id = g.guest_id\nWHERE res.status IN ('Occupied', 'CheckedIn');"}, {"role": "user", "content": "Add the property name to the result and sort the list by property name, then by room number."}, {"role": "assistant", "content": "SELECT p.property_name, r.room_number, g.first_name || ' ' || g.last_name AS guest_full_name\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.rooms r ON res.room_id = r.room_id\nJOIN hospitality_technology.guests g ON res.guest_id = g.guest_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE res.status IN ('Occupied', 'CheckedIn')\nORDER BY p.property_name, r.room_number;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "For each player, count the total number of achievements they've unlocked."}, {"role": "assistant", "content": "SELECT player_id,\n COUNT(*) AS total_achievements\nFROM gaming_technology.player_achievements\nGROUP BY player_id;"}, {"role": "user", "content": "Exclude players with fewer than 10 achievements."}, {"role": "assistant", "content": "SELECT player_id,\n COUNT(*) AS total_achievements\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Additionally, provide the month when they achieved their 10th achievement. Show player_id, total_achievements, and the month of the 10th unlock."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id,\n unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at) AS rn\n FROM gaming_technology.player_achievements\n),\ncounts AS (\n SELECT player_id,\n COUNT(*) AS total_achievements\n FROM gaming_technology.player_achievements\n GROUP BY player_id\n HAVING COUNT(*) >= 10\n)\nSELECT c.player_id,\n c.total_achievements,\n EXTRACT(MONTH FROM r.unlocked_at) AS tenth_achievement_month\nFROM counts c\nJOIN ranked r\n ON c.player_id = r.player_id\n AND r.rn = 10;"}, {"role": "user", "content": "Finally, order by total_achievements descending."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id,\n unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at) AS rn\n FROM gaming_technology.player_achievements\n),\ncounts AS (\n SELECT player_id,\n COUNT(*) AS total_achievements\n FROM gaming_technology.player_achievements\n GROUP BY player_id\n HAVING COUNT(*) >= 10\n)\nSELECT c.player_id,\n c.total_achievements,\n EXTRACT(MONTH FROM r.unlocked_at) AS tenth_achievement_month\nFROM counts c\nJOIN ranked r\n ON c.player_id = r.player_id\n AND r.rn = 10\nORDER BY c.total_achievements DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\n", "conversations": [{"role": "user", "content": "Show me a list of all customers from California along with their full names and phone numbers."}, {"role": "assistant", "content": "SELECT customer_id, first_name || ' ' || last_name AS full_name, phone_number FROM insurance.customers WHERE state = 'CA';"}, {"role": "user", "content": "Can you also include their email addresses in the results?"}, {"role": "assistant", "content": "SELECT customer_id, first_name || ' ' || last_name AS full_name, phone_number, email FROM insurance.customers WHERE state = 'CA';"}, {"role": "user", "content": "Actually, show me only those customers whose status is 'active'."}, {"role": "assistant", "content": "SELECT customer_id, first_name || ' ' || last_name AS full_name, phone_number, email FROM insurance.customers WHERE state = 'CA' AND status = 'active';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE 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 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_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 )\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 holdings from the `nft_holders` table where the `contract_type` is 'ERC721'. Show the wallet address, contract address, token ID, and amount held."}, {"role": "assistant", "content": "SELECT wallet_address, contract_address, token_id, CAST(amount AS DECIMAL) as amount FROM nft_holders WHERE contract_type = 'ERC721';"}, {"role": "user", "content": "For these ERC721 holdings, join with the `nft_metadata` table to get the `name` and `rarity_score` for each NFT. Only include NFTs where the rarity score is greater than 70."}, {"role": "assistant", "content": "SELECT nh.wallet_address, nh.contract_address, nh.token_id, nh.amount, nm.name, nm.rarity_score FROM nft_holders nh JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id WHERE nh.contract_type = 'ERC721' AND nm.rarity_score > 70;"}, {"role": "user", "content": "Now, group these results by the NFT collection, joining with `nft_collections` for Ethereum collections. Show the collection name, the average rarity score for NFTs in that collection (filtered above), and the total number of unique holders across all NFTs in that collection (from the initial filter). Only show collections with more than 50 unique holders, order by average rarity score descending, and limit to the top 10."}, {"role": "assistant", "content": "SELECT nc.name AS collection_name, AVG(nm.rarity_score) AS average_rarity_score, COUNT(DISTINCT nh.wallet_address) AS unique_holder_count FROM nft_holders nh JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id JOIN nft_collections nc ON nh.contract_address = nc.contract_address WHERE nh.contract_type = 'ERC721' AND nm.rarity_score > 70 AND nc.blockchain = 'Ethereum' GROUP BY nc.name HAVING COUNT(DISTINCT nh.wallet_address) > 50 ORDER BY average_rarity_score DESC LIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "Show me the username and registration date for players who do not have a last login recorded."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE last_login IS NULL;"}, {"role": "user", "content": "Also include their country code in the output."}, {"role": "assistant", "content": "SELECT username, registration_date, country_code FROM gaming_technology.players WHERE last_login IS NULL;"}, {"role": "user", "content": "Filter this list to only include players from the United Kingdom ('GB')."}, {"role": "assistant", "content": "SELECT username, registration_date, country_code FROM gaming_technology.players WHERE last_login IS NULL AND country_code = 'GB';"}, {"role": "user", "content": "Order the results by their registration date, from oldest to newest."}, {"role": "assistant", "content": "SELECT username, registration_date, country_code FROM gaming_technology.players WHERE last_login IS NULL AND country_code = 'GB' ORDER BY registration_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.loans ( loan_id text, account_id text, loan_type text, principal_amount numeric, current_principal_balance numeric, interest_rate numeric, term_months integer, origination_date date, maturity_date date, monthly_payment numeric, collateral_description text, status text )\n", "conversations": [{"role": "user", "content": "Show me all trades (trade_id, security_id, total_amount) where the trade_type is 'Buy' and the execution_venue is 'NYSE', along with the loan details (loan_type, principal_amount) for accounts that have both trades and loans."}, {"role": "assistant", "content": "SELECT t.trade_id, t.security_id, t.total_amount, l.loan_type, l.principal_amount FROM financial_services.trades t JOIN financial_services.loans l ON t.account_id = l.account_id WHERE t.trade_type = 'Buy' AND t.execution_venue = 'NYSE';"}, {"role": "user", "content": "Now modify the query to only include trades with a total_amount greater than $10,000 and loans with a principal_amount greater than $50,000, sorted by total_amount in descending order."}, {"role": "assistant", "content": "SELECT t.trade_id, t.security_id, t.total_amount, l.loan_type, l.principal_amount FROM financial_services.trades t JOIN financial_services.loans l ON t.account_id = l.account_id WHERE t.trade_type = 'Buy' AND t.execution_venue = 'NYSE' AND t.total_amount > 10000 AND l.principal_amount > 50000 ORDER BY t.total_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id character varying(64) NOT NULL, previous_block_id character varying(64), timestamp timestamp NOT NULL, nonce integer NOT NULL, merkle_root character varying(128) NOT NULL, difficulty integer NOT NULL, PRIMARY KEY (block_id) )\n", "conversations": [{"role": "user", "content": "Show me the block with the earliest timestamp and its corresponding previous block's difficulty level."}, {"role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b2.difficulty AS previous_block_difficulty FROM blockchain.blocks b1 LEFT JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id ORDER BY b1.timestamp ASC LIMIT 1;"}, {"role": "user", "content": "Now show me the same information but for the 5 earliest blocks instead of just one."}, {"role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b2.difficulty AS previous_block_difficulty FROM blockchain.blocks b1 LEFT JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id ORDER BY b1.timestamp ASC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id text PRIMARY KEY, post_id text, hashtag_id text )\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Show all notifications of type 'comment' with the content of the corresponding comment and the author's username."}, {"role": "assistant", "content": "SELECT n.notification_id,\n n.recipient_user_id,\n c.content AS comment_content,\n u.username\nFROM social_media.notifications n\nJOIN social_media.comments c\n ON n.target_entity_type = 'comment'\n AND n.target_entity_id = c.comment_id\nJOIN social_media.users u\n ON c.user_id = u.user_id\nWHERE n.notification_type = 'comment';"}, {"role": "user", "content": "Now restrict to notifications created within the last 7 days."}, {"role": "assistant", "content": "SELECT n.notification_id,\n n.recipient_user_id,\n c.content AS comment_content,\n u.username\nFROM social_media.notifications n\nJOIN social_media.comments c\n ON n.target_entity_type = 'comment'\n AND n.target_entity_id = c.comment_id\nJOIN social_media.users u\n ON c.user_id = u.user_id\nWHERE n.notification_type = 'comment'\n AND n.created_at >= CURRENT_DATE - INTERVAL '7 days';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )\n", "conversations": [{"role": "user", "content": "List all rooms with their latest review comment and the date of that review, showing the room number and property id."}, {"role": "assistant", "content": "SELECT r.room_number, r.property_id, rv.comment, rv.review_date\nFROM hospitality_technology.rooms r\nLEFT JOIN hospitality_technology.reviews rv\n ON r.property_id = rv.property_id\nWHERE rv.review_date = (\n SELECT MAX(rv2.review_date)\n FROM hospitality_technology.reviews rv2\n WHERE rv2.property_id = r.property_id\n);"}, {"role": "user", "content": "Can you also include the overall rating in the result?"}, {"role": "assistant", "content": "SELECT r.room_number, r.property_id, rv.comment, rv.rating_overall, rv.review_date\nFROM hospitality_technology.rooms r\nLEFT JOIN hospitality_technology.reviews rv\n ON r.property_id = rv.property_id\nWHERE rv.review_date = (\n SELECT MAX(rv2.review_date)\n FROM hospitality_technology.reviews rv2\n WHERE rv2.property_id = r.property_id\n);"}, {"role": "user", "content": "Show only rooms located on the 2nd floor."}, {"role": "assistant", "content": "SELECT r.room_number, r.property_id, rv.comment, rv.rating_overall, rv.review_date\nFROM hospitality_technology.rooms r\nLEFT JOIN hospitality_technology.reviews rv\n ON r.property_id = rv.property_id\nWHERE r.floor = 2\n AND rv.review_date = (\n SELECT MAX(rv2.review_date)\n FROM hospitality_technology.reviews rv2\n WHERE rv2.property_id = r.property_id\n);"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "Show reviews with an overall rating of 5, including the guest's full name and the property ID."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.property_id FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.reviews AS T2 ON T1.guest_id = T2.guest_id WHERE T2.rating_overall = 5;"}, {"role": "user", "content": "Can you also include the review date and order the results by review date descending?"}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.property_id, T2.review_date FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.reviews AS T2 ON T1.guest_id = T2.guest_id WHERE T2.rating_overall = 5 ORDER BY T2.review_date DESC;"}, {"role": "user", "content": "Actually, I only want reviews for properties with property IDs starting with 'P1' and where the review source is 'Online'."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.property_id, T2.review_date FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.reviews AS T2 ON T1.guest_id = T2.guest_id WHERE T2.rating_overall = 5 AND T2.property_id LIKE 'P1%' AND T2.review_source = 'Online' ORDER BY T2.review_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 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.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "For each employee who acts as a manager, please show the number of employees directly reporting to them."}, {"role": "assistant", "content": "SELECT m.first_name || ' ' || m.last_name AS manager_name, COUNT(e.employee_id) AS direct_report_count FROM financial_services.employees AS e JOIN financial_services.employees AS m ON e.manager_id = m.employee_id GROUP BY m.employee_id, manager_name;"}, {"role": "user", "content": "Include the department of the manager in the output as well."}, {"role": "assistant", "content": "SELECT m.first_name || ' ' || m.last_name AS manager_name, m.department, COUNT(e.employee_id) AS direct_report_count FROM financial_services.employees AS e JOIN financial_services.employees AS m ON e.manager_id = m.employee_id GROUP BY m.employee_id, manager_name, m.department;"}, {"role": "user", "content": "Only list managers who have fewer than 10 direct reports."}, {"role": "assistant", "content": "SELECT m.first_name || ' ' || m.last_name AS manager_name, m.department, COUNT(e.employee_id) AS direct_report_count FROM financial_services.employees AS e JOIN financial_services.employees AS m ON e.manager_id = m.employee_id GROUP BY m.employee_id, manager_name, m.department HAVING COUNT(e.employee_id) < 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "Get the count of service orders and total payment amount for each reservation."}, {"role": "assistant", "content": "SELECT so.reservation_id,\n COUNT(*) AS order_count,\n SUM(p.amount) AS total_payment\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.payments p\n ON so.reservation_id = p.reservation_id\nGROUP BY so.reservation_id\nORDER BY total_payment DESC;"}, {"role": "user", "content": "Actually, show only those reservations where the total number of service orders exceeds 3."}, {"role": "assistant", "content": "SELECT so.reservation_id,\n COUNT(*) AS order_count,\n SUM(p.amount) AS total_payment\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.payments p\n ON so.reservation_id = p.reservation_id\nGROUP BY so.reservation_id\nHAVING COUNT(*) > 3\nORDER BY total_payment DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "For each payment, list its payment_id, guest_id, payment_timestamp, and the next payment_id and next payment_timestamp made by the same guest."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.guest_id,\n p.payment_timestamp,\n n.payment_id AS next_payment_id,\n n.payment_timestamp AS next_payment_timestamp\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.payments n\n ON p.guest_id = n.guest_id\n AND n.payment_timestamp = (\n SELECT MIN(payment_timestamp)\n FROM hospitality_technology.payments\n WHERE guest_id = p.guest_id\n AND payment_timestamp > p.payment_timestamp\n );"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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) )\n", "conversations": [{"role": "user", "content": "List the reference number and status for all applications, including the registration date of the citizen who submitted it."}, {"role": "assistant", "content": "SELECT a.reference_number, a.status, c.registration_date FROM government_services.applications AS a JOIN citizens AS c ON a.citizen_id = c.citizen_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Give me the product name and description of all insurance products that have been updated in the last 30 days."}, {"role": "assistant", "content": "SELECT product_name, description FROM insurance.insurance_products WHERE updated_at >= NOW() - INTERVAL '30 days';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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)\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all assets that have at least one associated metadata entry, showing the asset name, symbol, and the key and value of each metadata entry."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, m.key, m.value FROM trading_platform.assets a JOIN trading_platform.metadata m ON a.asset_id = m.asset_id;"}, {"role": "user", "content": "Only show metadata entries where the metadata key contains the word 'link' or 'id'."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, m.key, m.value FROM trading_platform.assets a JOIN trading_platform.metadata m ON a.asset_id = m.asset_id WHERE m.key ILIKE '%link%' OR m.key ILIKE '%id%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\n", "conversations": [{"role": "user", "content": "I need to list all pairs of in-game items in the same game where one item is Epic and the other is Legendary, showing game_id, epic_item, and legendary_item."}, {"role": "assistant", "content": "SELECT a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary';"}, {"role": "user", "content": "Actually, only include pairs where both items have cost_amount greater than 100."}, {"role": "assistant", "content": "SELECT a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary'\n AND a.cost_amount > 100\n AND b.cost_amount > 100;"}, {"role": "user", "content": "Also, ensure each pair appears only once and avoid reversed duplicates."}, {"role": "assistant", "content": "SELECT DISTINCT\n LEAST(a.item_id::text, b.item_id::text) AS item1_id,\n GREATEST(a.item_id::text, b.item_id::text) AS item2_id,\n a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary'\n AND a.cost_amount > 100\n AND b.cost_amount > 100;"}, {"role": "user", "content": "Finally, order the results by game_id ascending."}, {"role": "assistant", "content": "SELECT DISTINCT\n LEAST(a.item_id::text, b.item_id::text) AS item1_id,\n GREATEST(a.item_id::text, b.item_id::text) AS item2_id,\n a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary'\n AND a.cost_amount > 100\n AND b.cost_amount > 100\nORDER BY a.game_id ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n", "conversations": [{"role": "user", "content": "Could you list the title of each game and the total quantity of items acquired by players for that specific game?"}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id GROUP BY g.title;"}, {"role": "user", "content": "Now, I only want to include games where the total acquired quantity is more than 100."}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id GROUP BY g.title HAVING SUM(pi.quantity) > 100;"}, {"role": "user", "content": "Please filter the results further to include only games from the 'Action' genre."}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id WHERE g.genre = 'Action' GROUP BY g.title HAVING SUM(pi.quantity) > 100;"}, {"role": "user", "content": "Finally, order the results by the total acquired quantity in descending order."}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id WHERE g.genre = 'Action' GROUP BY g.title HAVING SUM(pi.quantity) > 100 ORDER BY total_acquired_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, name character varying(150) NOT NULL, description text NOT NULL, icon_url character varying(255), points integer DEFAULT 0, hidden boolean DEFAULT false, PRIMARY KEY (achievement_id) )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n", "conversations": [{"role": "user", "content": "List the name and points of all hidden achievements."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true;"}, {"role": "user", "content": "Only include those with points greater than 50."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true\n AND points > 50;"}, {"role": "user", "content": "Now order the results by points in ascending order."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true\n AND points > 50\nORDER BY points ASC;"}, {"role": "user", "content": "Finally, limit the output to the top 10 entries."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true\n AND points > 50\nORDER BY points ASC\nLIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n", "conversations": [{"role": "user", "content": "Can you show the total quantity of all in-game items held by each player?"}, {"role": "assistant", "content": "SELECT player_id, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id;"}, {"role": "user", "content": "I'd like to see only players whose total quantity is over 20."}, {"role": "assistant", "content": "SELECT player_id, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20;"}, {"role": "user", "content": "Also, can you include the number of different unique items each player owns?"}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT item_id) AS unique_items, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20;"}, {"role": "user", "content": "Order the final result by unique_items descending, then by total_quantity descending."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT item_id) AS unique_items, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20\nORDER BY unique_items DESC, total_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )\n", "conversations": [{"role": "user", "content": "Show me all pairs of servers that are located in the same region, listing both server names and their region."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id;"}, {"role": "user", "content": "Filter this list to only include pairs where both servers are currently 'online'."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id WHERE s1.status = 'online' AND s2.status = 'online';"}, {"role": "user", "content": "For these pairs, also show the current_players for both servers."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region, s1.current_players AS server1_current_players, s2.current_players AS server2_current_players FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id WHERE s1.status = 'online' AND s2.status = 'online';"}, {"role": "user", "content": "Order the results by region ascending, then by the current players of the first server in the pair ascending."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region, s1.current_players AS server1_current_players, s2.current_players AS server2_current_players FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id WHERE s1.status = 'online' AND s2.status = 'online' ORDER BY s1.region ASC, s1.current_players ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid PRIMARY KEY, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n", "conversations": [{"role": "user", "content": "For each game, find the hidden achievement with the highest points and show the game title, achievement name, and points."}, {"role": "assistant", "content": "SELECT g.title AS game_title,\n a.name AS achievement_name,\n a.points\nFROM gaming_technology.achievements a\nJOIN gaming_technology.games g\n ON a.game_id = g.game_id\nWHERE a.hidden = true\n AND a.points = (\n SELECT MAX(points)\n FROM gaming_technology.achievements\n WHERE game_id = a.game_id\n AND hidden = true\n );"}, {"role": "user", "content": "Actually, exclude games that do not have any hidden achievements."}, {"role": "assistant", "content": "SELECT g.title AS game_title,\n a.name AS achievement_name,\n a.points\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a\n ON g.game_id = a.game_id\nWHERE a.hidden = true\n AND a.points = (\n SELECT MAX(points)\n FROM gaming_technology.achievements\n WHERE game_id = a.game_id\n AND hidden = true\n );"}, {"role": "user", "content": "Also, order the results by a.points descending."}, {"role": "assistant", "content": "SELECT g.title AS game_title,\n a.name AS achievement_name,\n a.points\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a\n ON g.game_id = a.game_id\nWHERE a.hidden = true\n AND a.points = (\n SELECT MAX(points)\n FROM gaming_technology.achievements\n WHERE game_id = a.game_id\n AND hidden = true\n )\nORDER BY a.points DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\n", "conversations": [{"role": "user", "content": "List all achievements with more than 100 points."}, {"role": "assistant", "content": "SELECT *\nFROM gaming_technology.achievements\nWHERE points > 100;"}, {"role": "user", "content": "Now exclude any hidden achievements."}, {"role": "assistant", "content": "SELECT *\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = false;"}, {"role": "user", "content": "Only show the columns achievement_id, name, and points."}, {"role": "assistant", "content": "SELECT achievement_id, name, points\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = false;"}, {"role": "user", "content": "Order the output by points in descending order and limit to top 5."}, {"role": "assistant", "content": "SELECT achievement_id, name, points\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = false\nORDER BY points DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\n", "conversations": [{"role": "user", "content": "List all servers that are currently online. Show their name, region, current player count, and maximum player capacity."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online';"}, {"role": "user", "content": "Filter the list to only include servers with a player utilization ratio (current_players / max_players) above 0.8."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online' AND max_players > 0 AND (CAST(current_players AS NUMERIC) / max_players) > 0.8;"}, {"role": "user", "content": "Also, exclude any servers where the maximum player capacity is less than 50."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online' AND max_players >= 50 AND (CAST(current_players AS NUMERIC) / max_players) > 0.8;"}, {"role": "user", "content": "Finally, order the results by player utilization ratio in descending order and limit the output to the top 10 servers."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online' AND max_players >= 50 AND (CAST(current_players AS NUMERIC) / max_players) > 0.8 ORDER BY (CAST(current_players AS NUMERIC) / max_players) DESC LIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid, player_id uuid, game_id uuid, server_id uuid, start_time timestamp with time zone, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n", "conversations": [{"role": "user", "content": "For each player, show the total number of achievements they have unlocked and their total game session count."}, {"role": "assistant", "content": "SELECT p.player_id, COUNT(pa.achievement_id) AS total_achievements_unlocked, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.player_achievements pa\nFULL JOIN gaming_technology.game_sessions gs ON pa.player_id = gs.player_id\nRIGHT JOIN (\n SELECT DISTINCT player_id FROM gaming_technology.player_achievements\n UNION\n SELECT DISTINCT player_id FROM gaming_technology.game_sessions\n) p ON pa.player_id = p.player_id OR gs.player_id = p.player_id\nGROUP BY p.player_id;"}, {"role": "user", "content": "Can you modify it to only include players who have unlocked at least 3 achievements and played at least 2 sessions?"}, {"role": "assistant", "content": "SELECT p.player_id, COUNT(pa.achievement_id) AS total_achievements_unlocked, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.player_achievements pa\nFULL JOIN gaming_technology.game_sessions gs ON pa.player_id = gs.player_id\nRIGHT JOIN (\n SELECT DISTINCT player_id FROM gaming_technology.player_achievements\n UNION\n SELECT DISTINCT player_id FROM gaming_technology.game_sessions\n) p ON pa.player_id = p.player_id OR gs.player_id = p.player_id\nGROUP BY p.player_id\nHAVING COUNT(pa.achievement_id) >= 3 AND COUNT(gs.session_id) >= 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\n", "conversations": [{"role": "user", "content": "List pairs of games that share the same publisher but belong to different genres, showing both titles and genres."}, {"role": "assistant", "content": "SELECT g1.game_id AS game1_id,\n g1.title AS title1,\n g1.genre AS genre1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.genre AS genre2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND g1.genre <> g2.genre;"}, {"role": "user", "content": "Exclude any pairs where the publisher_id is NULL."}, {"role": "assistant", "content": "SELECT g1.game_id AS game1_id,\n g1.title AS title1,\n g1.genre AS genre1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.genre AS genre2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND g1.genre <> g2.genre\nWHERE g1.publisher_id IS NOT NULL;"}, {"role": "user", "content": "Further restrict to game pairs released within one year of each other."}, {"role": "assistant", "content": "SELECT g1.game_id AS game1_id,\n g1.title AS title1,\n g1.release_date AS release1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.release_date AS release2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND ABS(EXTRACT(YEAR FROM AGE(g1.release_date, g2.release_date))) <= 1\nWHERE g1.publisher_id IS NOT NULL;"}, {"role": "user", "content": "Order the final result by publisher_id and then by the earliest release_date among each pair."}, {"role": "assistant", "content": "SELECT g1.publisher_id,\n g1.game_id AS game1_id,\n g1.title AS title1,\n g1.release_date AS release1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.release_date AS release2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND ABS(EXTRACT(YEAR FROM AGE(g1.release_date, g2.release_date))) <= 1\nWHERE g1.publisher_id IS NOT NULL\nORDER BY g1.publisher_id,\n LEAST(g1.release_date, g2.release_date) ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\nCREATE TABLE gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n", "conversations": [{"role": "user", "content": "List all in-game items of type 'Consumable', showing for each item the item name, cost amount, and the total number of players who have that item in their inventory."}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount;"}, {"role": "user", "content": "Can you also show the total quantity held by all players for each item?"}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count, COALESCE(SUM(pi.quantity), 0) AS total_quantity\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount;"}, {"role": "user", "content": "Only include items where the total quantity is at least 10."}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count, COALESCE(SUM(pi.quantity), 0) AS total_quantity\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount\nHAVING COALESCE(SUM(pi.quantity), 0) >= 10;"}, {"role": "user", "content": "Sort the results by total_quantity in descending order."}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count, COALESCE(SUM(pi.quantity), 0) AS total_quantity\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount\nHAVING COALESCE(SUM(pi.quantity), 0) >= 10\nORDER BY total_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\n", "conversations": [{"role": "user", "content": "List all game sessions that lasted longer than 30 minutes. Show the session_id, player_id, game_id, and duration_seconds."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800;"}, {"role": "user", "content": "Now, only include sessions that took place in the year 2023."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800 AND start_time >= '2023-01-01' AND start_time < '2024-01-01';"}, {"role": "user", "content": "Filter these sessions further to only show those with a score greater than 100."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800 AND start_time >= '2023-01-01' AND start_time < '2024-01-01' AND score > 100;"}, {"role": "user", "content": "Order the results by score in descending order and show only the top 5 entries."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800 AND start_time >= '2023-01-01' AND start_time < '2024-01-01' AND score > 100 ORDER BY score DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\n", "conversations": [{"role": "user", "content": "Show the number of achievements unlocked by each player per month. Display player_id, month (as YYYY-MM), and achievement_count."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM');"}, {"role": "user", "content": "Filter to months where players unlocked at least 5 achievements."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5;"}, {"role": "user", "content": "Sort the results by year_month ascending and then by achievement_count descending."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5\nORDER BY year_month ASC, achievement_count DESC;"}, {"role": "user", "content": "Limit the results to 10 rows."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5\nORDER BY year_month ASC, achievement_count DESC\nLIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n", "conversations": [{"role": "user", "content": "Can you list for each player their most recent and second most recent achievements, showing columns player_id, recent_achievement_id, second_recent_achievement_id, and recent_unlocked_at?"}, {"role": "assistant", "content": "SELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n prev.achievement_id AS second_recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at\nFROM (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn\n FROM gaming_technology.player_achievements\n) recent\nJOIN (\n SELECT player_id, achievement_id,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn\n FROM gaming_technology.player_achievements\n) prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1 AND prev.rn = 2;"}, {"role": "user", "content": "Actually, please exclude any players who have less than two unlock records."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n prev.achievement_id AS second_recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1\n AND prev.rn = 2\n AND recent.cnt >= 2;"}, {"role": "user", "content": "Also include the unlocked_at timestamp of the second most recent achievement."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at,\n prev.achievement_id AS second_recent_achievement_id,\n prev.unlocked_at AS second_recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1\n AND prev.rn = 2\n AND recent.cnt >= 2;"}, {"role": "user", "content": "Finally, order the output by recent_unlocked_at in descending order."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at,\n prev.achievement_id AS second_recent_achievement_id,\n prev.unlocked_at AS second_recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1 AND prev.rn = 2 AND recent.cnt >= 2\nORDER BY recent.unlocked_at DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\n", "conversations": [{"role": "user", "content": "For each server, what is the earliest and latest start time of its sessions?"}, {"role": "assistant", "content": "SELECT server_id, MIN(start_time), MAX(start_time) FROM gaming_technology.game_sessions GROUP BY server_id;"}, {"role": "user", "content": "Only show servers where the difference between the earliest and latest session is more than 30 days."}, {"role": "assistant", "content": "SELECT server_id, MIN(start_time), MAX(start_time) FROM gaming_technology.game_sessions GROUP BY server_id HAVING MAX(start_time) - MIN(start_time) > INTERVAL '30 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\n", "conversations": [{"role": "user", "content": "List all posts created by user 'U100' in March 2024."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01';"}, {"role": "user", "content": "Only show posts with `media_type` 'video'."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at, media_type FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01' AND media_type = 'video';"}, {"role": "user", "content": "Order them by creation time descending and limit to the top 10."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at, media_type FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01' AND media_type = 'video' ORDER BY created_at DESC LIMIT 10;"}, {"role": "user", "content": "Also, only include posts with `visibility` 'public'."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at, media_type, visibility FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01' AND media_type = 'video' AND visibility = 'public' ORDER BY created_at DESC LIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'suppliers'. Mapping: { properties: { supplier_id: { type: 'keyword' }, supplier_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, address: { type: 'text' }, country: { type: 'keyword' }, contact_person: { type: 'text', index: false }, contact_email: { type: 'keyword' }, quality_rating: { type: 'float' }, certified_date: { type: 'date' } } }. Document _id can be supplier_id.\n", "conversations": [{"role": "user", "content": "특정 국가의 모든 공급업체 정보를 조회하고 싶습니다. 국가 이름, 공급업체 이름, 주소, 품질 등급을 포함해 주세요."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\"]\n}"}, {"role": "user", "content": "품질 등급이 3.5 이상인 공급업체만 보고 싶습니다. 어떻게 수정해야 하나요?"}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\"]\n}"}, {"role": "user", "content": "인증 날짜가 2020년 이후인 공급업체만 추가로 필터링하고 싶습니다."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n },\n {\n \"range\": {\n \"certified_date\": {\n \"gte\": \"2020-01-01\"\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\", \"certified_date\"]\n}"}, {"role": "user", "content": "결과를 품질 등급 기준으로 내림차순 정렬해 주세요."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n },\n {\n \"range\": {\n \"certified_date\": {\n \"gte\": \"2020-01-01\"\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\", \"certified_date\"],\n \"sort\": [\n {\n \"quality_rating\": {\n \"order\": \"desc\"\n }\n }\n ]\n}"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all beneficiaries who are listed as 'Sibling' or 'Parent' on policies where their share is between 20 and 60 percent. Include beneficiary_id, policy_id, first_name, last_name, relationship, and percentage_share."}, {"role": "assistant", "content": "SELECT beneficiary_id, policy_id, first_name, last_name, relationship, percentage_share\nFROM insurance.policy_beneficiaries\nWHERE relationship IN ('Sibling', 'Parent')\n AND percentage_share BETWEEN 20 AND 60;"}, {"role": "user", "content": "Actually, could you also include the contact_info for each beneficiary and only show beneficiaries who were added after January 1, 2024?"}, {"role": "assistant", "content": "SELECT beneficiary_id, policy_id, first_name, last_name, relationship, percentage_share, contact_info\nFROM insurance.policy_beneficiaries\nWHERE relationship IN ('Sibling', 'Parent')\n AND percentage_share BETWEEN 20 AND 60\n AND added_at > '2024-01-01';"}, {"role": "user", "content": "Only include beneficiaries where contact_info is not null and sort the results by added_at descending."}, {"role": "assistant", "content": "SELECT beneficiary_id, policy_id, first_name, last_name, relationship, percentage_share, contact_info, added_at\nFROM insurance.policy_beneficiaries\nWHERE relationship IN ('Sibling', 'Parent')\n AND percentage_share BETWEEN 20 AND 60\n AND added_at > '2024-01-01'\n AND contact_info IS NOT NULL\nORDER BY added_at DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nNode Label ':AircraftModel'. Properties: { model_id: String (Constraint: UNIQUE), model_name: String, manufacturer: String, passenger_capacity: Integer, max_range_km: Integer, engine_type: String, wingspan_m: Float, status: String, first_flight_date: Date }. Index on model_id.\nNode Label ':Material'. Properties: { material_id: String (Constraint: UNIQUE), material_name: String, specification: String, description: String, density_kg_m3: Float, tensile_strength_mpa: Integer }. Index on material_id.\nNode Label ':AssemblyLine'. Properties: { line_id: String (Constraint: UNIQUE), line_name: String, location_building: String, location_area: String, capacity_units_per_month: Integer, status: String }. Relationship: (:AssemblyLine)-[:BUILDS_MODEL]->(:AircraftModel {model_id}). Index on line_id.\nNode Label ':AssemblyStep'. Properties: { step_id: String (Constraint: UNIQUE), step_number: Integer, step_name: String, description: String, standard_duration_hours: Float, required_skill_level: String, workstation: String }. Relationship: (:AssemblyLine {line_id})-[:HAS_STEP {sequence: }]->(:AssemblyStep). Index on step_id.\nNode Label ':AircraftBuild'. Properties: { build_id: String (Constraint: UNIQUE), serial_number: String (Constraint: UNIQUE), build_start_date: Datetime, estimated_completion_date: Date, actual_completion_date: Datetime, current_status: String, customer_order_id: String }. Relationships: (:AircraftBuild)-[:IS_MODEL]->(:AircraftModel {model_id}), (:AircraftBuild)-[:ASSEMBLED_ON]->(:AssemblyLine {line_id}). Index on build_id, serial_number, current_status.\nNode Label ':Employee'. Properties: { employee_id: String (Constraint: UNIQUE), first_name: String, last_name: String, job_title: String, skill_certifications: String[], hire_date: Date, employment_status: String }. Relationships: (:Employee)-[:ASSIGNED_TO]->(:AssemblyLine {line_id}), (:Employee)-[:REPORTS_TO]->(:Employee {employee_id as supervisor_id}). Index on employee_id.\nNode Label ':InventoryBatch'. Properties: { inventory_record_id: String (Constraint: UNIQUE), quantity: Integer, location_warehouse: String, location_bin: String, received_date: Datetime, expiry_date: Date, batch_number: String, last_updated: Datetime }. Relationship: (:InventoryBatch)-[:IS_INSTANCE_OF]->(:Component {component_id}). Index on inventory_record_id, component_id.\n", "conversations": [{"role": "user", "content": "Can you help me fetch the inventory details for components associated with a specific aircraft build, including the batch number, quantity, and warehouse location?"}, {"role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}, {"role": "user", "content": "Can you modify this to show only inventory batches received after a specific date, say June 1, 2023?"}, {"role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01')\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}, {"role": "user", "content": "What if I also want to exclude batches with quantities less than 10?"}, {"role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01') AND ib.quantity >= 10\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\n", "conversations": [{"role": "user", "content": "List all hashtag names and their creation dates."}, {"role": "assistant", "content": "SELECT tag_name, created_at FROM social_media.hashtags;"}, {"role": "user", "content": "Please only include hashtags created in the year 2023."}, {"role": "assistant", "content": "SELECT tag_name, created_at FROM social_media.hashtags WHERE created_at >= '2023-01-01' AND created_at < '2024-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id.text, username.text, email.text, password_hash.text, full_name.text, profile_picture_url.text, bio.text, location.text, created_at.timestamp, updated_at.timestamp, is_verified.boolean )\n", "conversations": [{"role": "user", "content": "How many users were registered in each month of 2024?"}, {"role": "assistant", "content": "SELECT date_trunc('month', created_at) AS month, COUNT(*) AS user_count\nFROM social_media.users\nWHERE created_at >= '2024-01-01'\n AND created_at < '2025-01-01'\nGROUP BY month\nORDER BY month;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all pairs of hashtags created within the same hour, including both hashtag IDs and their creation timestamps."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.created_at AS created1, h2.hashtag_id AS hashtag2_id, h2.created_at AS created2 FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id;"}, {"role": "user", "content": "Actually, I also want to include the time difference in minutes between the two hashtags."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.created_at AS created1, h2.hashtag_id AS hashtag2_id, h2.created_at AS created2, EXTRACT(EPOCH FROM (h2.created_at - h1.created_at)) / 60 AS diff_minutes FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id;"}, {"role": "user", "content": "Also, filter to only include pairs where both tag names start with the letter 'T'."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.tag_name AS tag1, h2.hashtag_id AS hashtag2_id, h2.tag_name AS tag2, EXTRACT(EPOCH FROM (h2.created_at - h1.created_at)) / 60 AS diff_minutes FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id WHERE h1.tag_name LIKE 'T%' AND h2.tag_name LIKE 'T%';"}, {"role": "user", "content": "Finally, order the results by the earlier creation timestamp in descending order."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.tag_name AS tag1, h2.hashtag_id AS hashtag2_id, h2.tag_name AS tag2, EXTRACT(EPOCH FROM (h2.created_at - h1.created_at)) / 60 AS diff_minutes FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id WHERE h1.tag_name LIKE 'T%' AND h2.tag_name LIKE 'T%' ORDER BY LEAST(h1.created_at, h2.created_at) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (doctor_id) )\nCREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, appointment_time timestamp with time zone NOT NULL, duration_minutes integer NOT NULL, reason text, status character varying(32) NOT NULL, location_id character varying(64), notes text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n", "conversations": [{"role": "user", "content": "Can you show me the count of new doctors added each month in 2023? Return the month and number of doctors."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', created_at) AS month, COUNT(*) AS doctor_count\nFROM healthcare.doctors\nWHERE created_at >= '2023-01-01' AND created_at < '2024-01-01'\nGROUP BY DATE_TRUNC('month', created_at);"}, {"role": "user", "content": "Actually, include the month as the first day of the month and order the results by month in descending order."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', created_at)::date AS month_start, COUNT(*) AS doctor_count\nFROM healthcare.doctors\nWHERE created_at >= '2023-01-01' AND created_at < '2024-01-01'\nGROUP BY DATE_TRUNC('month', created_at)\nORDER BY month_start DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n", "conversations": [{"role": "user", "content": "What is the average number of refills allowed across all prescriptions?"}, {"role": "assistant", "content": "SELECT AVG(refills_allowed) FROM healthcare.prescriptions;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\n", "conversations": [{"role": "user", "content": "List the medication_id, medication_name, and description for all medications whose generic_name starts with 'A'."}, {"role": "assistant", "content": "SELECT medication_id, medication_name, description\nFROM healthcare.medications\nWHERE generic_name LIKE 'A%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "Show me a list of all patient names along with the full names of their doctors for appointments scheduled in February 2024."}, {"role": "assistant", "content": "SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nWHERE a.status = 'Scheduled' AND DATE_TRUNC('month', a.appointment_time) = DATE '2024-02-01';"}, {"role": "user", "content": "Actually, can you also include the appointment time for each result?"}, {"role": "assistant", "content": "SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nWHERE a.status = 'Scheduled' AND DATE_TRUNC('month', a.appointment_time) = DATE '2024-02-01';"}, {"role": "user", "content": "I got an error: column 'appointment_time' does not exist. Can you check and fix the query?"}, {"role": "assistant", "content": "SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nWHERE a.status = 'Scheduled' AND DATE_TRUNC('month', a.appointment_time) = DATE '2024-02-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\n", "conversations": [{"role": "user", "content": "List appointment IDs, patient first and last names, and their chief complaint for appointments that have an associated medical record."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.first_name, p.last_name, mr.chief_complaint\nFROM healthcare.appointments a\nJOIN healthcare.medical_records mr\n ON a.appointment_id = mr.appointment_id\nJOIN healthcare.patients p\n ON a.patient_id = p.patient_id;"}, {"role": "user", "content": "Also include the appointment_time and only include records from the past 30 days."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.first_name, p.last_name, mr.chief_complaint, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.medical_records mr\n ON a.appointment_id = mr.appointment_id\nJOIN healthcare.patients p\n ON a.patient_id = p.patient_id\nWHERE mr.record_date >= NOW() - INTERVAL '30 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n", "conversations": [{"role": "user", "content": "Show me a list of all appointments and the number of prescriptions that were issued on the same day for each appointment."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time::date AS appointment_date,\n COUNT(pr.prescription_id) AS prescriptions_count\nFROM healthcare.appointments a\nLEFT JOIN healthcare.medical_records mr ON mr.appointment_id = a.appointment_id\nLEFT JOIN healthcare.prescriptions pr ON pr.record_id = mr.record_id\nGROUP BY a.appointment_id, a.appointment_time::date;"}, {"role": "user", "content": "Only include appointments where at least one prescription was made that day, and show the full names of the patient and doctor for each appointment."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time::date AS appointment_date,\n p.first_name || ' ' || p.last_name AS patient_full_name,\n d.first_name || ' ' || d.last_name AS doctor_full_name,\n COUNT(pr.prescription_id) AS prescriptions_count\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nLEFT JOIN healthcare.medical_records mr ON mr.appointment_id = a.appointment_id\nLEFT JOIN healthcare.prescriptions pr ON pr.record_id = mr.record_id\nGROUP BY a.appointment_id, a.appointment_time::date, p.first_name, p.last_name, d.first_name, d.last_name\nHAVING COUNT(pr.prescription_id) > 0;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\n", "conversations": [{"role": "user", "content": "List the description and diagnosis date for all diagnoses that are marked as chronic and were made in the year 2023."}, {"role": "assistant", "content": "SELECT description, diagnosis_date FROM healthcare.diagnoses WHERE is_chronic = true AND diagnosis_date BETWEEN '2023-01-01' AND '2023-12-31';"}, {"role": "user", "content": "Also include the patient ID and order the results by diagnosis date ascending."}, {"role": "assistant", "content": "SELECT patient_id, description, diagnosis_date FROM healthcare.diagnoses WHERE is_chronic = true AND diagnosis_date BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY diagnosis_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n", "conversations": [{"role": "user", "content": "List all prescriptions with medication details. Return prescription_id, patient full name, medication_name, and prescription_date."}, {"role": "assistant", "content": "SELECT pr.prescription_id,\n p.first_name || ' ' || p.last_name AS patient_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.prescriptions pr\nJOIN healthcare.patients p ON pr.patient_id = p.patient_id\nJOIN healthcare.medications m ON pr.medication_id = m.medication_id;"}, {"role": "user", "content": "Filter to only include prescriptions where the quantity_dispensed is greater than 30."}, {"role": "assistant", "content": "SELECT pr.prescription_id,\n p.first_name || ' ' || p.last_name AS patient_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.prescriptions pr\nJOIN healthcare.patients p ON pr.patient_id = p.patient_id\nJOIN healthcare.medications m ON pr.medication_id = m.medication_id\nWHERE pr.quantity_dispensed > 30;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n", "conversations": [{"role": "user", "content": "List each patient's first and last name along with the insurance plan name they are enrolled in, including only primary policies. Return patient_id, first_name, last_name, and plan_name."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n ip.plan_name\nFROM healthcare.patients AS p\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id AND pi.is_primary = true\nJOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id;"}, {"role": "user", "content": "Now limit to plans with plan_type 'EPO' and sort by patient last name ascending."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n ip.plan_name\nFROM healthcare.patients AS p\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id AND pi.is_primary = true\nJOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id\nWHERE ip.plan_type = 'EPO'\nORDER BY p.last_name ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (doctor_id) )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "Show a list of diagnoses along with the chief complaint noted in the corresponding medical record. Display diagnosis description, diagnosis date, and the chief complaint."}, {"role": "assistant", "content": "SELECT T1.description, T1.diagnosis_date, T2.chief_complaint FROM healthcare.diagnoses AS T1 JOIN healthcare.medical_records AS T2 ON T1.record_id = T2.record_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n", "conversations": [{"role": "user", "content": "Show each patient's policy number, the associated insurance plan ID, and any medications they have been prescribed, including the medication ID and prescription date."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.plan_id, pr.medication_id, pr.prescription_date\nFROM healthcare.patient_insurance pi\nJOIN healthcare.prescriptions pr ON pi.patient_id = pr.patient_id;"}, {"role": "user", "content": "Only include prescriptions that were made after the insurance policy's effective date."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.plan_id, pr.medication_id, pr.prescription_date\nFROM healthcare.patient_insurance pi\nJOIN healthcare.prescriptions pr ON pi.patient_id = pr.patient_id\nWHERE pr.prescription_date >= pi.effective_date;"}, {"role": "user", "content": "Add the expiration date of the insurance policy and only show records where the prescription was made before the policy expired."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.plan_id, pi.expiration_date, pr.medication_id, pr.prescription_date\nFROM healthcare.patient_insurance pi\nJOIN healthcare.prescriptions pr ON pi.patient_id = pr.patient_id\nWHERE pr.prescription_date >= pi.effective_date\n AND (pi.expiration_date IS NULL OR pr.prescription_date < pi.expiration_date);"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all medical records along with the chief complaint and record date for patients who had their medical record created after March 1, 2023 and whose record was created by doctor with ID 'doctor_123'."}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01';"}, {"role": "user", "content": "Can you also include the treatment plan for each record in the result?"}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date, treatment_plan FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01';"}, {"role": "user", "content": "Actually, I only want records where the assessment field is not null."}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date, treatment_plan FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01' AND assessment IS NOT NULL;"}, {"role": "user", "content": "Now, restrict the results to records where the chief complaint contains the word 'cough'."}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date, treatment_plan FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01' AND assessment IS NOT NULL AND chief_complaint ILIKE '%cough%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "Show me all primary insurance policies along with their policy numbers and effective dates for patient with ID 'patient_555'."}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE;"}, {"role": "user", "content": "Can you also show the group number for each policy?"}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE;"}, {"role": "user", "content": "I only want to see those policies that are still active."}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE AND expiration_date > CURRENT_DATE;"}, {"role": "user", "content": "Actually, can you order the results by expiration_date, with the soonest expiration first?"}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE AND expiration_date > CURRENT_DATE ORDER BY expiration_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\n", "conversations": [{"role": "user", "content": "Can you show me the total number of diagnosis records for each doctor, along with the doctor's ID? Please include only those diagnoses marked as 'chronic'."}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS total_chronic_diagnoses FROM healthcare.diagnoses WHERE is_chronic = TRUE GROUP BY doctor_id;"}, {"role": "user", "content": "Now, can you also include the average number of chronic diagnoses per patient for each doctor in the results?"}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS total_chronic_diagnoses, COUNT(*)::FLOAT / COUNT(DISTINCT patient_id) AS avg_chronic_per_patient FROM healthcare.diagnoses WHERE is_chronic = TRUE GROUP BY doctor_id;"}, {"role": "user", "content": "Please filter the results to only include doctors with at least 5 chronic diagnoses."}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS total_chronic_diagnoses, COUNT(*)::FLOAT / COUNT(DISTINCT patient_id) AS avg_chronic_per_patient FROM healthcare.diagnoses WHERE is_chronic = TRUE GROUP BY doctor_id HAVING COUNT(*) >= 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all medical records created by doctor 'doctor_001' for patients who had their last medical record on or after '2024-01-01', including record_id, patient_id, record_date, chief_complaint, and doctor_id."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, mr.record_date, mr.chief_complaint, mr.doctor_id\nFROM healthcare.medical_records mr\nJOIN (\n SELECT patient_id, MAX(record_date) AS last_record_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) last_rec ON mr.patient_id = last_rec.patient_id\nWHERE mr.doctor_id = 'doctor_001' AND last_rec.last_record_date >= '2024-01-01';"}, {"role": "user", "content": "Please refine the results to only include records where the 'assessment' field is not null."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, mr.record_date, mr.chief_complaint, mr.doctor_id\nFROM healthcare.medical_records mr\nJOIN (\n SELECT patient_id, MAX(record_date) AS last_record_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) last_rec ON mr.patient_id = last_rec.patient_id\nWHERE mr.doctor_id = 'doctor_001' AND last_rec.last_record_date >= '2024-01-01' AND mr.assessment IS NOT NULL;"}, {"role": "user", "content": "I received too many results. Can you only show records where 'treatment_plan' is also not null?"}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, mr.record_date, mr.chief_complaint, mr.doctor_id\nFROM healthcare.medical_records mr\nJOIN (\n SELECT patient_id, MAX(record_date) AS last_record_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) last_rec ON mr.patient_id = last_rec.patient_id\nWHERE mr.doctor_id = 'doctor_001' AND last_rec.last_record_date >= '2024-01-01' AND mr.assessment IS NOT NULL AND mr.treatment_plan IS NOT NULL;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "List the medication IDs and names for all entries where the description is missing or empty."}, {"role": "assistant", "content": "SELECT medication_id, medication_name FROM healthcare.medications WHERE description IS NULL OR description = '';"}, {"role": "user", "content": "For those medications, please also show the manufacturer and sort the results by medication name in ascending order."}, {"role": "assistant", "content": "SELECT medication_id, medication_name, manufacturer FROM healthcare.medications WHERE description IS NULL OR description = '' ORDER BY medication_name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\n", "conversations": [{"role": "user", "content": "Count the number of users whose location is 'London'."}, {"role": "assistant", "content": "SELECT count(*) FROM social_media.users WHERE location = 'London';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text )\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": "Show the first and last name of each citizen and the count of their scheduled appointments."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, COUNT(a.appointment_id) AS scheduled_appointment_count FROM government_services.citizens AS c JOIN government_services.appointments AS a ON c.citizen_id = a.citizen_id WHERE a.status = 'Scheduled' GROUP BY c.citizen_id, c.first_name, c.last_name;"}, {"role": "user", "content": "Only include citizens who have more than 2 scheduled appointments."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, COUNT(a.appointment_id) AS scheduled_appointment_count FROM government_services.citizens AS c JOIN government_services.appointments AS a ON c.citizen_id = a.citizen_id WHERE a.status = 'Scheduled' GROUP BY c.citizen_id, c.first_name, c.last_name HAVING COUNT(a.appointment_id) > 2;"}, {"role": "user", "content": "I got an error with that query. Let's simplify. Just show the first name, last name, and the total number of all appointments (regardless of status) for each citizen."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, COUNT(a.appointment_id) AS total_appointment_count FROM government_services.citizens AS c JOIN government_services.appointments AS a ON c.citizen_id = a.citizen_id GROUP BY c.citizen_id, c.first_name, c.last_name;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n", "conversations": [{"role": "user", "content": "List all policies where the premium_amount exceeds the base_premium of its insurance product. Display the policy_number, premium_amount, product_name, and base_premium. Sort the results by premium_amount descending."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nORDER BY p.premium_amount DESC;"}, {"role": "user", "content": "Actually, I only want policies that are active and whose insurance products are also active."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'active'\n AND ip.is_active = TRUE\nORDER BY p.premium_amount DESC;"}, {"role": "user", "content": "Also, limit the output to policies with a coverage_limit greater than 1000000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'active'\n AND ip.is_active = TRUE\n AND p.coverage_limit > 1000000\nORDER BY p.premium_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, 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 the first name, last name, and contact information for beneficiaries added before 2023."}, {"role": "assistant", "content": "SELECT first_name, last_name, contact_info FROM insurance.policy_beneficiaries WHERE added_at < '2023-01-01';"}, {"role": "user", "content": "Now, only include beneficiaries with a 'Child' relationship and add their percentage share to the output."}, {"role": "assistant", "content": "SELECT first_name, last_name, contact_info, percentage_share FROM insurance.policy_beneficiaries WHERE added_at < '2023-01-01' AND relationship = 'Child';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id 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.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "Find currently employed employees whose direct manager has been terminated. Display the employee's full name, hire date, manager's full name, and manager's termination date."}, {"role": "assistant", "content": "SELECT e.employee_id,\n CONCAT(e.first_name, ' ', e.last_name) AS employee_full_name,\n e.hire_date,\n CONCAT(m.first_name, ' ', m.last_name) AS manager_full_name,\n m.termination_date\nFROM government_services.employees e\nJOIN government_services.employees m ON e.manager_employee_id = m.employee_id\nWHERE e.termination_date IS NULL\n AND m.termination_date IS NOT NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.applications ( application_id.text, citizen_id.text, service_id.text, submitted_at.timestamp, status.text, last_updated_at.timestamp, assigned_employee_id.text, decision_date.date, notes.text, reference_number.text )\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "Show me a list of all appointment IDs, the name of the service associated with each appointment, and the location name where it is scheduled."}, {"role": "assistant", "content": "SELECT appt.appointment_id, srv.service_id, loc.location_name\nFROM government_services.appointments appt\nJOIN government_services.service_locations loc ON appt.location_id = loc.location_id\nJOIN government_services.applications appl ON appl.citizen_id = appt.citizen_id AND appl.service_id = appt.service_id\nJOIN government_services.applications app ON app.service_id = appt.service_id\nJOIN government_services.service_locations sloc ON appt.location_id = sloc.location_id;"}, {"role": "user", "content": "Actually, can you also include the scheduled start time for each appointment in the result?"}, {"role": "assistant", "content": "SELECT appt.appointment_id, srv.service_id, loc.location_name, appt.scheduled_start_time\nFROM government_services.appointments appt\nJOIN government_services.service_locations loc ON appt.location_id = loc.location_id\nJOIN government_services.applications appl ON appl.citizen_id = appt.citizen_id AND appl.service_id = appt.service_id\nJOIN government_services.applications app ON app.service_id = appt.service_id\nJOIN government_services.service_locations sloc ON appt.location_id = sloc.location_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.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.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text )\nCREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Find all vehicles that have at least one fuel log and at least one maintenance log. For each vehicle, show vehicle_id, make, model, the date of its most recent maintenance, and the timestamp of its earliest fuel log."}, {"role": "assistant", "content": "SELECT v.vehicle_id,\n v.make,\n v.model,\n MAX(m.service_date) AS last_service_date,\n MIN(f.log_timestamp) AS first_fuel_log_timestamp\nFROM transportation.vehicles v\nJOIN transportation.maintenance_logs m\n ON v.vehicle_id = m.vehicle_id\nJOIN transportation.fuel_logs f\n ON v.vehicle_id = f.vehicle_id\nGROUP BY v.vehicle_id, v.make, v.model;"}, {"role": "user", "content": "Now only include vehicles where the earliest fuel log occurred before the most recent maintenance service."}, {"role": "assistant", "content": "SELECT v.vehicle_id,\n v.make,\n v.model,\n MAX(m.service_date) AS last_service_date,\n MIN(f.log_timestamp) AS first_fuel_log_timestamp\nFROM transportation.vehicles v\nJOIN transportation.maintenance_logs m\n ON v.vehicle_id = m.vehicle_id\nJOIN transportation.fuel_logs f\n ON v.vehicle_id = f.vehicle_id\nGROUP BY v.vehicle_id, v.make, v.model\nHAVING MIN(f.log_timestamp) < MAX(m.service_date);"}, {"role": "user", "content": "Also include the odometer reading at the most recent maintenance and the quantity of the earliest fuel log, and order the results by the time difference between the maintenance and fuel log in descending order."}, {"role": "assistant", "content": "WITH last_maint AS (\n SELECT ml.vehicle_id,\n ml.odometer_reading,\n ml.service_date\n FROM transportation.maintenance_logs ml\n JOIN (\n SELECT vehicle_id, MAX(service_date) AS max_date\n FROM transportation.maintenance_logs\n GROUP BY vehicle_id\n ) mx\n ON ml.vehicle_id = mx.vehicle_id\n AND ml.service_date = mx.max_date\n), first_fuel AS (\n SELECT fl.vehicle_id,\n fl.quantity,\n fl.log_timestamp\n FROM transportation.fuel_logs fl\n JOIN (\n SELECT vehicle_id, MIN(log_timestamp) AS min_ts\n FROM transportation.fuel_logs\n GROUP BY vehicle_id\n ) mn\n ON fl.vehicle_id = mn.vehicle_id\n AND fl.log_timestamp = mn.min_ts\n)\nSELECT v.vehicle_id,\n v.make,\n v.model,\n lm.odometer_reading AS last_odo,\n ff.quantity AS first_fuel_qty,\n (lm.service_date - ff.log_timestamp) AS time_diff\nFROM last_maint lm\nJOIN first_fuel ff\n ON lm.vehicle_id = ff.vehicle_id\nJOIN transportation.vehicles v\n ON v.vehicle_id = lm.vehicle_id\nORDER BY time_diff DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show the count of invoices for each case ID."}, {"role": "assistant", "content": "SELECT case_id, COUNT(invoice_id) AS invoice_count FROM legal_services.invoices WHERE case_id IS NOT NULL GROUP BY case_id ORDER BY invoice_count DESC"}, {"role": "user", "content": "Only include case IDs with more than 2 invoices."}, {"role": "assistant", "content": "SELECT case_id, COUNT(invoice_id) AS invoice_count FROM legal_services.invoices WHERE case_id IS NOT NULL GROUP BY case_id HAVING COUNT(invoice_id) > 2 ORDER BY invoice_count DESC"}, {"role": "user", "content": "For these cases, what is the average total amount across all invoices?"}, {"role": "assistant", "content": "SELECT case_id, COUNT(invoice_id) AS invoice_count, AVG(total_amount) AS average_total_amount FROM legal_services.invoices WHERE case_id IS NOT NULL GROUP BY case_id HAVING COUNT(invoice_id) > 2 ORDER BY average_total_amount DESC"}, {"role": "user", "content": "Order the results by average total amount ascending."}, {"role": "assistant", "content": "SELECT case_id, COUNT(invoice_id) AS invoice_count, AVG(total_amount) AS average_total_amount FROM legal_services.invoices WHERE case_id IS NOT NULL GROUP BY case_id HAVING COUNT(invoice_id) > 2 ORDER BY average_total_amount ASC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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", "conversations": [{"role": "user", "content": "How many smart money addresses are in the top 100 rank?"}, {"role": "assistant", "content": "SELECT count(address) FROM smart_money_profit WHERE rank <= 100"}, {"role": "user", "content": "Okay, can you break that down by `chain`? Show the count for each chain where the rank is 100 or better."}, {"role": "assistant", "content": "SELECT chain, count(address) FROM smart_money_profit WHERE rank <= 100 GROUP BY chain"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars (\n car_id character varying(64) NOT NULL, -- Unique identifier for the train car\n train_id character varying(64) NOT NULL, -- Foreign key referencing trains\n car_number character varying(10) NOT NULL, -- Identifier of the car within the train set\n car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage\n class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars)\n capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars)\n features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom')\n PRIMARY KEY (car_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id)\n)\nCREATE TABLE train_station_management.routes (\n route_id character varying(64) NOT NULL, -- Unique identifier for the route\n route_name character varying(128) NOT NULL, -- Name of the route (e.g., 'Northeast Corridor')\n description text, -- Description of the route\n origin_station_id character varying(64) NOT NULL, -- Starting station\n destination_station_id character varying(64) NOT NULL, -- Final station\n is_active boolean NOT NULL DEFAULT true, -- Is the route currently operational?\n PRIMARY KEY (route_id),\n FOREIGN KEY (origin_station_id) REFERENCES train_station_management.stations(station_id),\n FOREIGN KEY (destination_station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.route_stations (\n route_station_id character varying(64) NOT NULL, -- Unique ID for this route-station link\n route_id character varying(64) NOT NULL, -- Foreign key referencing routes\n station_id character varying(64) NOT NULL, -- Foreign key referencing stations\n sequence_order integer NOT NULL, -- Order of the station in the route (1 for origin, 2, 3...)\n distance_from_previous_km numeric(10, 2), -- Distance from the previous station in the sequence\n typical_stop_duration_minutes integer, -- Typical dwell time at this station\n PRIMARY KEY (route_station_id),\n UNIQUE (route_id, station_id),\n UNIQUE (route_id, sequence_order),\n FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id),\n FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.schedules (\n schedule_id character varying(64) NOT NULL, -- Unique identifier for a specific scheduled trip\n train_id character varying(64) NOT NULL, -- Foreign key referencing the train used\n route_id character varying(64) NOT NULL, -- Foreign key referencing the route taken\n departure_datetime timestamp with time zone NOT NULL, -- Scheduled departure time from origin station\n arrival_datetime timestamp with time zone NOT NULL, -- Scheduled arrival time at destination station\n status character varying(32) NOT NULL DEFAULT 'Scheduled', -- e.g., Scheduled, On Time, Delayed, Cancelled, Arrived\n notes text, -- Any notes regarding this specific trip (e.g., reason for delay)\n PRIMARY KEY (schedule_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id),\n FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id)\n)\nCREATE TABLE train_station_management.passengers (\n passenger_id character varying(64) NOT NULL, -- Unique identifier for the passenger\n first_name character varying(100) NOT NULL, -- Passenger's first name\n last_name character varying(100) NOT NULL, -- Passenger's last name\n email character varying(128) UNIQUE, -- Passenger's email address\n phone_number character varying(32) UNIQUE, -- Passenger's phone number\n date_of_birth date, -- Passenger's date of birth\n loyalty_program_id character varying(64), -- ID for loyalty program, if applicable\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE train_station_management.bookings (\n booking_id character varying(64) NOT NULL, -- Unique identifier for the booking\n passenger_id character varying(64) NOT NULL, -- Foreign key referencing the passenger\n schedule_id character varying(64) NOT NULL, -- Foreign key referencing the scheduled trip\n booking_datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the booking was made\n status character varying(32) NOT NULL DEFAULT 'Confirmed', -- e.g., Confirmed, Cancelled, Pending\n total_price numeric(12, 2) NOT NULL, -- Total price for all tickets in this booking\n currency_code character varying(3) NOT NULL DEFAULT 'USD', -- Currency of the price\n special_requests text, -- Any special requests (e.g., wheelchair assistance)\n PRIMARY KEY (booking_id),\n FOREIGN KEY (passenger_id) REFERENCES train_station_management.passengers(passenger_id),\n FOREIGN KEY (schedule_id) REFERENCES train_station_management.schedules(schedule_id)\n)\nCREATE TABLE train_station_management.staff (\n staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew\n primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff)\n employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier\n hire_date date NOT NULL,\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed?\n PRIMARY KEY (staff_id),\n FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id)\n)\n", "conversations": [{"role": "user", "content": "Can you help me retrieve the details of all bookings for a specific route with route_id 'RT789', including the passenger names and the scheduled departure times?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nWHERE s.route_id = 'RT789';"}, {"role": "user", "content": "Can you modify the query to include only bookings with a status of 'Pending'?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending';"}, {"role": "user", "content": "Can you also add the route name and origin station ID to the results?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price, r.route_name, r.origin_station_id\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nJOIN train_station_management.routes r ON s.route_id = r.route_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending';"}, {"role": "user", "content": "Can you sort the results by departure datetime in descending order?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price, r.route_name, r.origin_station_id\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nJOIN train_station_management.routes r ON s.route_id = r.route_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending'\nORDER BY s.departure_datetime DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "I need to find patients who received prescriptions within 7 days after their latest appointment. Show patient_id, first and last name, appointment_time, prescription_date, and medication_name."}, {"role": "assistant", "content": "WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id"}, {"role": "user", "content": "Actually, restrict it to prescriptions where dosage contains 'mg'."}, {"role": "assistant", "content": "WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\n AND pr.dosage LIKE '%mg%'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id"}, {"role": "user", "content": "Also, sort the results by prescription_date descending and limit to 5."}, {"role": "assistant", "content": "WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\n AND pr.dosage LIKE '%mg%'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id\nORDER BY pr.prescription_date DESC\nLIMIT 5"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "Show a list of patients along with their most recent diagnoses, including patient ID, diagnosis description, and the diagnosis date."}, {"role": "assistant", "content": "SELECT d.patient_id, d.description AS diagnosis_description, d.diagnosis_date FROM healthcare.diagnoses d INNER JOIN (SELECT patient_id, MAX(diagnosis_date) AS latest_date FROM healthcare.diagnoses GROUP BY patient_id) latest ON d.patient_id = latest.patient_id AND d.diagnosis_date = latest.latest_date;"}, {"role": "user", "content": "Add the doctor's full name who made each diagnosis to the results."}, {"role": "assistant", "content": "SELECT d.patient_id, doc.first_name || ' ' || doc.last_name AS doctor_full_name, d.description AS diagnosis_description, d.diagnosis_date FROM healthcare.diagnoses d INNER JOIN (SELECT patient_id, MAX(diagnosis_date) AS latest_date FROM healthcare.diagnoses GROUP BY patient_id) latest ON d.patient_id = latest.patient_id AND d.diagnosis_date = latest.latest_date INNER JOIN healthcare.doctors doc ON d.doctor_id = doc.doctor_id;"}, {"role": "user", "content": "Could you also include the diagnosis code in the output?"}, {"role": "assistant", "content": "SELECT d.patient_id, doc.first_name || ' ' || doc.last_name AS doctor_full_name, d.diagnosis_code, d.description AS diagnosis_description, d.diagnosis_date FROM healthcare.diagnoses d INNER JOIN (SELECT patient_id, MAX(diagnosis_date) AS latest_date FROM healthcare.diagnoses GROUP BY patient_id) latest ON d.patient_id = latest.patient_id AND d.diagnosis_date = latest.latest_date INNER JOIN healthcare.doctors doc ON d.doctor_id = doc.doctor_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "I need a count of appointments per patient that took place between '2024-04-01' and '2024-04-30', showing patient_id, first_name, last_name, and the total number of appointments."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nWHERE a.appointment_time BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY p.patient_id, p.first_name, p.last_name;"}, {"role": "user", "content": "Only include patients who had at least 2 appointments in that period."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nWHERE a.appointment_time BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY p.patient_id, p.first_name, p.last_name\nHAVING COUNT(a.appointment_id) >= 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "Find all medications whose NDC code starts with '0003'. Show the medication ID and NDC code."}, {"role": "assistant", "content": "SELECT medication_id, ndc_code FROM healthcare.medications WHERE ndc_code LIKE '0003%';"}, {"role": "user", "content": "Count the number of medications for each manufacturer and show manufacturers with more than 100 medications."}, {"role": "assistant", "content": "SELECT manufacturer, COUNT(*) AS medication_count FROM healthcare.medications GROUP BY manufacturer HAVING COUNT(*) > 100;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n", "conversations": [{"role": "user", "content": "For each reservation in the last three months, show the reservation ID, check-in date, number of adults, and the corresponding room type name."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.check_in_date, r.num_adults, rt.type_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nWHERE r.created_at >= NOW() - INTERVAL '3 months';"}, {"role": "user", "content": "Also include the name of the property for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.check_in_date, r.num_adults, rt.type_name, p.property_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE r.created_at >= NOW() - INTERVAL '3 months';"}, {"role": "user", "content": "Sort the results by number of adults descending, and then by check-in date ascending."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.check_in_date, r.num_adults, rt.type_name, p.property_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE r.created_at >= NOW() - INTERVAL '3 months'\nORDER BY r.num_adults DESC, r.check_in_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "List all services in the 'Concierge' department along with their names, price, and whether they are currently available. Include the property name as well."}, {"role": "assistant", "content": "SELECT s.service_name, s.price, s.is_available, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.department = 'Concierge';"}, {"role": "user", "content": "Could you filter only those services that are not currently available and sort by price ascending?"}, {"role": "assistant", "content": "SELECT s.service_name, s.price, s.is_available, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.department = 'Concierge'\n AND s.is_available = false\nORDER BY s.price ASC;"}, {"role": "user", "content": "Instead, show only properties in the city of 'Miami' and add the service category to the results."}, {"role": "assistant", "content": "SELECT s.service_name, s.category, s.price, s.is_available, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.department = 'Concierge'\n AND s.is_available = false\n AND p.city = 'Miami'\nORDER BY s.price ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "List all staff members, showing their full name, position, and the name of the property where they work."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.position, T2.property_name FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id;"}, {"role": "user", "content": "Only include staff who are currently active and add their manager's full name if they have one."}, {"role": "assistant", "content": "SELECT T1.first_name AS staff_first_name, T1.last_name AS staff_last_name, T1.position, T2.property_name, T3.first_name AS manager_first_name, T3.last_name AS manager_last_name FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id LEFT JOIN hospitality_technology.staff AS T3 ON T1.manager_id = T3.staff_id WHERE T1.is_active = TRUE;"}, {"role": "user", "content": "Filter further to only include staff working at properties in the 'California' state and sort by property name, then staff last name."}, {"role": "assistant", "content": "SELECT T1.first_name AS staff_first_name, T1.last_name AS staff_last_name, T1.position, T2.property_name, T3.first_name AS manager_first_name, T3.last_name AS manager_last_name FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id LEFT JOIN hospitality_technology.staff AS T3 ON T1.manager_id = T3.staff_id WHERE T1.is_active = TRUE AND T2.state_province = 'California' ORDER BY T2.property_name, T1.last_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all staff members hired in 2024, showing their first name, last name, and hire date."}, {"role": "assistant", "content": "SELECT first_name, last_name, hire_date FROM hospitality_technology.staff WHERE EXTRACT(YEAR FROM hire_date) = 2024"}, {"role": "user", "content": "Now, only include those whose position is 'Manager'."}, {"role": "assistant", "content": "SELECT first_name, last_name, hire_date FROM hospitality_technology.staff WHERE EXTRACT(YEAR FROM hire_date) = 2024 AND position = 'Manager'"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.reservations ( reservation_id.text, property_id.text, guest_id.text, room_id.text, room_type_id.text, check_in_date.date, check_out_date.date, actual_check_in_ts.timestamp, actual_check_out_ts.timestamp, num_adults.integer, num_children.integer, status.text, booking_source.text, rate_plan_id.text, total_amount.numeric, amount_paid.numeric, special_requests.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "For each property, list the names of all available services in the 'Wellness' category. Show property name and service name."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.service_name FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.services AS T2 ON T1.property_id = T2.property_id WHERE T2.category = 'Wellness' AND T2.is_available = TRUE ORDER BY T1.property_name, T2.service_name;"}, {"role": "user", "content": "Now, filter those services to only include ones with a price less than 75 and also include the department and price in the output."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.service_name, T2.department, T2.price FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.services AS T2 ON T1.property_id = T2.property_id WHERE T2.category = 'Wellness' AND T2.is_available = TRUE AND T2.price < 75 ORDER BY T1.property_name, T2.service_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\nCREATE TABLE hospitality_technology.reservations (\n reservation_id character varying(64) NOT NULL, -- unique identifier for the booking\n property_id character varying(64) NOT NULL, -- FK to properties table\n guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)\n room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)\n room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)\n check_in_date date NOT NULL, -- scheduled check-in date\n check_out_date date NOT NULL, -- scheduled check-out date\n actual_check_in_ts timestamp with time zone, -- actual check-in time\n actual_check_out_ts timestamp with time zone, -- actual check-out time\n num_adults integer NOT NULL, -- number of adults\n num_children integer DEFAULT 0, -- number of children\n status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow\n booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn\n rate_plan_id character varying(64), -- FK to rate_plans table (optional)\n total_amount numeric(12, 2), -- estimated or final total cost\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n special_requests text, -- specific guest requests for this booking\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (reservation_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.services ( service_id.text, property_id.text, service_name.text, description.text, category.text, price.numeric, unit.text, is_available.boolean, department.text )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "For each guest, show their full name and the total quantity of services they have ordered in the last 30 days."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.quantity) AS total_quantity\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.order_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY g.guest_id, g.first_name, g.last_name;"}, {"role": "user", "content": "Now only include guests whose total_quantity is greater than 10, and order by total_quantity descending."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.quantity) AS total_quantity\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.order_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY g.guest_id, g.first_name, g.last_name\nHAVING SUM(so.quantity) > 10\nORDER BY total_quantity DESC;"}, {"role": "user", "content": "Also include the total spending for each of these guests in that period."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.quantity) AS total_quantity,\n ROUND(SUM(so.total_price), 2) AS total_spending\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.order_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY g.guest_id, g.first_name, g.last_name\nHAVING SUM(so.quantity) > 10\nORDER BY total_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\n", "conversations": [{"role": "user", "content": "Show the average base rate and maximum occupancy of room types grouped by property_type."}, {"role": "assistant", "content": "SELECT p.property_type,\n AVG(rt.base_rate) AS avg_base_rate,\n MAX(rt.max_occupancy) AS max_occupancy\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.room_types rt\n ON p.property_id = rt.property_id\nGROUP BY p.property_type;"}, {"role": "user", "content": "Only include those property types where the average base rate is greater than 200."}, {"role": "assistant", "content": "SELECT p.property_type,\n AVG(rt.base_rate) AS avg_base_rate,\n MAX(rt.max_occupancy) AS max_occupancy\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.room_types rt\n ON p.property_id = rt.property_id\nGROUP BY p.property_type\nHAVING AVG(rt.base_rate) > 200;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve all room types with a base_rate above 150 for each property."}, {"role": "assistant", "content": "SELECT property_id, type_name, base_rate\nFROM hospitality_technology.room_types\nWHERE base_rate > 150;"}, {"role": "user", "content": "Also filter to only include room types with max_occupancy >= 3."}, {"role": "assistant", "content": "SELECT property_id, type_name, base_rate\nFROM hospitality_technology.room_types\nWHERE base_rate > 150\n AND max_occupancy >= 3;"}, {"role": "user", "content": "Finally, show guest first and last names of guests created after '2023-01-01' who could book these room types."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, rt.property_id, rt.type_name, rt.base_rate\nFROM hospitality_technology.room_types rt\nCROSS JOIN hospitality_technology.guests g\nWHERE rt.base_rate > 150\n AND rt.max_occupancy >= 3\n AND g.created_at > '2023-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\n", "conversations": [{"role": "user", "content": "List all room types along with their property name, bed type, and base rate for properties located in Canada, ordered by base rate descending."}, {"role": "assistant", "content": "SELECT rt.type_name, p.property_name, rt.bed_type, rt.base_rate\nFROM hospitality_technology.room_types rt\nJOIN hospitality_technology.properties p\n ON rt.property_id = p.property_id\nWHERE p.country_code = 'CA'\nORDER BY rt.base_rate DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "For each property, show the property name and the count of staff members with the position 'Manager'."}, {"role": "assistant", "content": "SELECT\n p.property_name,\n COUNT(s.staff_id) AS manager_count\nFROM hospitality_technology.properties AS p\nJOIN hospitality_technology.staff AS s\n ON p.property_id = s.property_id\nWHERE\n s.position = 'Manager'\nGROUP BY\n p.property_name;"}, {"role": "user", "content": "Now, only include properties located in the state of 'California' and sort the results by the count of managers descending."}, {"role": "assistant", "content": "SELECT\n p.property_name,\n COUNT(s.staff_id) AS manager_count\nFROM hospitality_technology.properties AS p\nJOIN hospitality_technology.staff AS s\n ON p.property_id = s.property_id\nWHERE\n s.position = 'Manager' AND p.state_province = 'California'\nGROUP BY\n p.property_name\nORDER BY\n manager_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\n", "conversations": [{"role": "user", "content": "List all rooms, showing their room number, type name, and the name of the property they are in."}, {"role": "assistant", "content": "SELECT T1.room_number, T2.type_name, T3.property_name FROM hospitality_technology.rooms AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.room_type_id = T2.room_type_id JOIN hospitality_technology.properties AS T3 ON T1.property_id = T3.property_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_profit ( address.text, rank.numeric, profit.numeric, roi.numeric, realized_ratio.numeric, most_profit_token.text, last_trade_time.text, chain.text )\n", "conversations": [{"role": "user", "content": "List the top 3 addresses with the highest profit on the Arbitrum chain, including roi and most_profit_token."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}, {"role": "user", "content": "Please add the realized_ratio and last_trade_time for each result."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token, realized_ratio, last_trade_time FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n", "conversations": [{"role": "user", "content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?"}, {"role": "assistant", "content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n", "conversations": [{"role": "user", "content": "Which are the top 3 tokens on BSC by total USD value held by all CEXs, and what is their narrative and current price?"}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "Can you also show, for each token, the number of CEX addresses holding it?"}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, COUNT(DISTINCT ctb.address) AS cex_address_count, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "Only include tokens with total USD value above 1,000,000."}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, COUNT(DISTINCT ctb.address) AS cex_address_count, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nHAVING SUM(ctb.usd_value) > 1000000\nORDER BY total_usd_value DESC\nLIMIT 3;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\n", "conversations": [{"role": "user", "content": "Show the tokens with a negative net flow this month on all chains."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now());"}, {"role": "user", "content": "Order them by net flow ascending and only show the bottom 5."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now()) ORDER BY net_flow ASC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\n", "conversations": [{"role": "user", "content": "List addresses on the 'Ethereum' chain that have an ROI greater than 5 and a profit greater than $1000. Show their address, profit, ROI, and realized ratio."}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000"}, {"role": "user", "content": "Can you order these addresses by their profit in descending order?"}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000 ORDER BY profit DESC"}, {"role": "user", "content": "Only show addresses whose last trade time is in 2024."}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000 AND last_trade_time LIKE '2024%' ORDER BY profit DESC"}, {"role": "user", "content": "Include the rank of these addresses in the output and show only the top 5 results."}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio, rank FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000 AND last_trade_time LIKE '2024%' ORDER BY profit DESC LIMIT 5"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )\nCREATE TABLE financial_services.transactions ( transaction_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, related_account_id character varying(64), transaction_type character varying(50) NOT NULL, amount numeric(19, 4) NOT NULL, currency character varying(3) NOT NULL, transaction_date timestamp NOT NULL, effective_date date NOT NULL, description text, status character varying(32) NOT NULL, reference_number character varying(128), PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data (\n data_point_id bigserial NOT NULL, -- auto-incrementing primary key\n security_id character varying(64) NOT NULL, -- identifier for the security\n data_timestamp timestamp NOT NULL, -- timestamp for the data point (e.g., end of day, intraday)\n open_price numeric(19, 8), -- opening price for the period\n high_price numeric(19, 8), -- highest price during the period\n low_price numeric(19, 8), -- lowest price during the period\n close_price numeric(19, 8) NOT NULL, -- closing price for the period\n adjusted_close_price numeric(19, 8), -- closing price adjusted for dividends and splits\n volume bigint, -- trading volume during the period\n source character varying(50), -- source of the market data (e.g., Bloomberg, Refinitiv)\n PRIMARY KEY (data_point_id),\n UNIQUE (security_id, data_timestamp), -- Ensure unique data point per security per time\n FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id)\n)\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n", "conversations": [{"role": "user", "content": "Which customers have traded securities with the highest average trading amount per trade across all their accounts? Show me the customer full name, email, and the average trade amount for each customer."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS full_name, c.email, AVG(t.total_amount) AS avg_trade_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email;"}, {"role": "user", "content": "Actually, I'd like to see only those customers whose average trade amount is above 5000 and who have executed at least 3 trades. Can you add those filters and show the customer id too?"}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, c.email, AVG(t.total_amount) AS avg_trade_amount, COUNT(t.trade_id) AS trade_count\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email\nHAVING AVG(t.total_amount) > 5000 AND COUNT(t.trade_id) >= 3;"}, {"role": "user", "content": "I'd also like to see the total traded quantity per customer in this result. Please include it and sort the output by avg_trade_amount descending."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, c.email, AVG(t.total_amount) AS avg_trade_amount, COUNT(t.trade_id) AS trade_count, SUM(t.quantity) AS total_traded_quantity\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email\nHAVING AVG(t.total_amount) > 5000 AND COUNT(t.trade_id) >= 3\nORDER BY avg_trade_amount DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.accounts ( account_id.text, customer_id.text, account_number.text, account_type.text, balance.numeric, currency.text, opened_date.date, status.text, interest_rate.numeric, last_updated_at.timestamp )\nCREATE TABLE financial_services.transactions ( transaction_id.text, account_id.text, related_account_id.text, transaction_type.text, amount.numeric, currency.text, transaction_date.timestamp, effective_date.date, description.text, status.text, reference_number.text )\nCREATE TABLE financial_services.securities ( security_id.text, ticker_symbol.text, isin_code.text, cusip_code.text, security_name.text, security_type.text, exchange.text, currency.text, issuer_name.text, sector.text, last_updated.timestamp )\nCREATE TABLE financial_services.employees ( employee_id.text, first_name.text, last_name.text, job_title.text, department.text, branch_id.text, email.text, phone_extension.text, hire_date.date, termination_date.date, manager_id.text, status.text )\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n", "conversations": [{"role": "user", "content": "Show me all employees (employee_id, first_name, last_name) in the 'Investment' department who have processed loans (loan_id) with a principal amount greater than $100,000, along with the count of such loans for each employee."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name, e.last_name, COUNT(l.loan_id) AS loan_count\nFROM financial_services.employees e\nJOIN financial_services.loans l ON e.employee_id = l.account_id\nWHERE e.department = 'Investment' AND l.principal_amount > 100000\nGROUP BY e.employee_id, e.first_name, e.last_name"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.trades ( trade_id text, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "Can you list all securities that have had at least one trade in the past 30 days? Please include the ticker_symbol, security_name, exchange, and the total number of trades for each security."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY s.ticker_symbol, s.security_name, s.exchange;"}, {"role": "user", "content": "I want to see the average trade quantity as well for each security in the same result."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count, AVG(t.quantity) AS avg_quantity\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY s.ticker_symbol, s.security_name, s.exchange;"}, {"role": "user", "content": "I need only those securities where the average trade quantity is above 100. Please order by avg_quantity descending."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count, AVG(t.quantity) AS avg_quantity\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY s.ticker_symbol, s.security_name, s.exchange\nHAVING AVG(t.quantity) > 100\nORDER BY avg_quantity DESC;"}, {"role": "user", "content": "Instead, show only securities traded on the 'NASDAQ' or 'NYSE' exchanges."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count, AVG(t.quantity) AS avg_quantity\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\n AND s.exchange IN ('NASDAQ', 'NYSE')\nGROUP BY s.ticker_symbol, s.security_name, s.exchange\nHAVING AVG(t.quantity) > 100\nORDER BY avg_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\n", "conversations": [{"role": "user", "content": "Give me the number of active customers grouped by city."}, {"role": "assistant", "content": "SELECT city, COUNT(*) AS customer_count FROM financial_services.customers WHERE status = 'Active' GROUP BY city;"}, {"role": "user", "content": "Actually, only include cities with at least 10 active customers."}, {"role": "assistant", "content": "SELECT city, COUNT(*) AS customer_count FROM financial_services.customers WHERE status = 'Active' GROUP BY city HAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Also, order the results by customer_count ascending."}, {"role": "assistant", "content": "SELECT city, COUNT(*) AS customer_count FROM financial_services.customers WHERE status = 'Active' GROUP BY city HAVING COUNT(*) >= 10 ORDER BY customer_count ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.trades ( trade_id.text, account_id.text, security_id.text, order_id.text, trade_type.text, quantity.numeric, price_per_unit.numeric, total_amount.numeric, commission.numeric, trade_timestamp.timestamp, settlement_date.date, status.text, execution_venue.text )\nCREATE TABLE financial_services.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "For each employee who serves as a relationship manager, what is the total transaction amount processed for the accounts they manage?"}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, SUM(t.amount) AS total_managed_transaction_amount FROM financial_services.employees e JOIN financial_services.accounts a ON e.employee_id = a.relationship_manager_id JOIN financial_services.transactions t ON a.account_id = t.account_id GROUP BY e.employee_id, e.first_name, e.last_name;"}, {"role": "user", "content": "Only include transactions with a status of 'Completed' in this calculation."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, SUM(t.amount) AS total_managed_transaction_amount FROM financial_services.employees e JOIN financial_services.accounts a ON e.employee_id = a.relationship_manager_id JOIN financial_services.transactions t ON a.account_id = t.account_id WHERE t.status = 'Completed' GROUP BY e.employee_id, e.first_name, e.last_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "Find all distinct pairs of customers having the same first_name but living in different cities. Display a.customer_id, a.first_name, a.city AS city_a, b.customer_id, b.city AS city_b."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a,\n a.first_name,\n a.city AS city_a,\n b.customer_id AS customer_id_b,\n b.city AS city_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.first_name = b.first_name\n AND a.city <> b.city\n AND a.customer_id < b.customer_id;"}, {"role": "user", "content": "Only include pairs where both customers have status 'Active'."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a,\n a.first_name,\n a.city AS city_a,\n b.customer_id AS customer_id_b,\n b.city AS city_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.first_name = b.first_name\n AND a.city <> b.city\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active';"}, {"role": "user", "content": "Sort the output by first_name ascending and then by customer_id_a ascending."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a,\n a.first_name,\n a.city AS city_a,\n b.customer_id AS customer_id_b,\n b.city AS city_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.first_name = b.first_name\n AND a.city <> b.city\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\nORDER BY a.first_name ASC,\n customer_id_a ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "I want to see pairs of customers living in the same state but having different risk profiles. Show their customer_ids, states, and risk_profiles."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile;"}, {"role": "user", "content": "Exclude any pairs where either customer has a null phone_number."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL;"}, {"role": "user", "content": "Ensure each pair appears only once, without reversed duplicates."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL AND a.customer_id < b.customer_id;"}, {"role": "user", "content": "Finally, only include states that have more than 3 customers in total."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL AND a.customer_id < b.customer_id AND a.state IN (SELECT state FROM financial_services.customers GROUP BY state HAVING COUNT(*) > 3);"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities (\n security_id character varying(64) NOT NULL, -- unique identifier for the security\n ticker_symbol character varying(20) NOT NULL UNIQUE, -- stock ticker or fund symbol\n isin_code character varying(12) UNIQUE, -- International Securities Identification Number\n cusip_code character varying(9) UNIQUE, -- CUSIP number\n security_name text NOT NULL, -- full name of the security\n security_type character varying(50) NOT NULL, -- e.g., Stock, Bond, ETF, Mutual Fund, Option, Future\n exchange character varying(50), -- primary exchange where traded (e.g., NYSE, NASDAQ)\n currency character varying(3) NOT NULL, -- currency the security is denominated in\n issuer_name character varying(255), -- name of the issuing entity\n sector character varying(100), -- industry sector\n last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (security_id)\n)\n", "conversations": [{"role": "user", "content": "List pairs of securities that trade on different exchanges but belong to the same sector, showing ticker_symbol of both as symbol_a and symbol_b, their exchanges, and the sector."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.ticker_symbol < b.ticker_symbol;"}, {"role": "user", "content": "Actually, exclude any pairs where the sector is NULL and ensure uniqueness by requiring symbol_a < symbol_b."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.sector IS NOT NULL\n AND a.ticker_symbol < b.ticker_symbol;"}, {"role": "user", "content": "Now also order the results by sector ascending and symbol_a ascending."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.sector IS NOT NULL\n AND a.ticker_symbol < b.ticker_symbol\nORDER BY a.sector ASC, a.ticker_symbol ASC;"}, {"role": "user", "content": "Finally, only include pairs where both securities are denominated in USD."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.sector IS NOT NULL\n AND a.currency = 'USD'\n AND b.currency = 'USD'\n AND a.ticker_symbol < b.ticker_symbol\nORDER BY a.sector ASC, a.ticker_symbol ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id text PRIMARY KEY, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions ( transaction_id text PRIMARY KEY, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )\nCREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "List all employees and the branch they work at, along with their job title and department."}, {"role": "assistant", "content": "SELECT employee_id, first_name || ' ' || last_name AS full_name, job_title, department, branch_id\nFROM financial_services.employees;"}, {"role": "user", "content": "Add the full name of each employee's manager to the result. If there is no manager, show NULL."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS full_name, e.job_title, e.department, e.branch_id, m.first_name || ' ' || m.last_name AS manager_full_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;"}, {"role": "user", "content": "Only include employees who are currently active, and sort the list by department, then by full_name."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS full_name, e.job_title, e.department, e.branch_id, m.first_name || ' ' || m.last_name AS manager_full_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.status = 'Active'\nORDER BY e.department, full_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\n", "conversations": [{"role": "user", "content": "List all securities (security_id, ticker_symbol, security_name) that have a currency of 'EUR' and were last updated within the last 30 days, along with their exchange and sector information."}, {"role": "assistant", "content": "SELECT security_id, ticker_symbol, security_name, exchange, sector FROM financial_services.securities WHERE currency = 'EUR' AND last_updated >= CURRENT_DATE - INTERVAL '30 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\n", "conversations": [{"role": "user", "content": "Provide for each security its ticker_symbol, the most recent close_price and corresponding timestamp."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, md.close_price, md.data_timestamp\nFROM financial_services.market_data md\nJOIN financial_services.securities s ON md.security_id = s.security_id\nWHERE md.data_timestamp = (\n SELECT MAX(md2.data_timestamp)\n FROM financial_services.market_data md2\n WHERE md2.security_id = md.security_id\n);"}, {"role": "user", "content": "Actually, I'd like to filter to only those securities where the latest adjusted_close_price is at least 2% higher than the previous data point."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT md.security_id, s.ticker_symbol, md.data_timestamp, md.adjusted_close_price,\n LAG(md.adjusted_close_price) OVER (PARTITION BY md.security_id ORDER BY md.data_timestamp) AS prev_adj\n FROM financial_services.market_data md\n JOIN financial_services.securities s ON md.security_id = s.security_id\n)\nSELECT r.ticker_symbol, r.data_timestamp AS latest_timestamp, r.adjusted_close_price\nFROM ranked r\nWHERE r.data_timestamp = (\n SELECT MAX(r2.data_timestamp) FROM ranked r2 WHERE r2.security_id = r.security_id\n )\n AND r.adjusted_close_price >= r.prev_adj * 1.02;"}, {"role": "user", "content": "The SQL gives errors about ambiguous column names. Please fully qualify all columns and table aliases."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT md.security_id, s.ticker_symbol, md.data_timestamp, md.adjusted_close_price,\n LAG(md.adjusted_close_price) OVER (PARTITION BY md.security_id ORDER BY md.data_timestamp) AS prev_adj\n FROM financial_services.market_data AS md\n JOIN financial_services.securities AS s ON md.security_id = s.security_id\n)\nSELECT ranked.ticker_symbol,\n ranked.data_timestamp AS latest_timestamp,\n ranked.adjusted_close_price\nFROM ranked\nWHERE ranked.data_timestamp = (\n SELECT MAX(r2.data_timestamp)\n FROM ranked AS r2\n WHERE r2.security_id = ranked.security_id\n )\n AND ranked.adjusted_close_price >= ranked.prev_adj * 1.02;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve all orders placed after '2024-06-01', including order_id, user_id, asset_id, quantity, and price."}, {"role": "assistant", "content": "SELECT order_id, user_id, asset_id, quantity, price\nFROM trading_platform.orders\nWHERE created_at > '2024-06-01';"}, {"role": "user", "content": "Actually, only include orders for assets whose metadata key is 'category' and value is 'cryptocurrency'."}, {"role": "assistant", "content": "SELECT o.order_id, o.user_id, o.asset_id, o.quantity, o.price\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m ON o.asset_id = m.asset_id\nWHERE o.created_at > '2024-06-01'\n AND m.key = 'category' AND m.value = 'cryptocurrency';"}, {"role": "user", "content": "Now, count the number of such orders per asset, along with the asset_id."}, {"role": "assistant", "content": "SELECT o.asset_id, COUNT(*) AS order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m ON o.asset_id = m.asset_id\nWHERE o.created_at > '2024-06-01'\n AND m.key = 'category' AND m.value = 'cryptocurrency'\nGROUP BY o.asset_id;"}, {"role": "user", "content": "Finally, only show assets with more than 5 such orders, ordered by order_count descending."}, {"role": "assistant", "content": "SELECT o.asset_id, COUNT(*) AS order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m ON o.asset_id = m.asset_id\nWHERE o.created_at > '2024-06-01'\n AND m.key = 'category' AND m.value = 'cryptocurrency'\nGROUP BY o.asset_id\nHAVING COUNT(*) > 5\nORDER BY order_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n", "conversations": [{"role": "user", "content": "Count the number of metadata entries for each asset."}, {"role": "assistant", "content": "SELECT asset_id, COUNT(*) AS metadata_count\nFROM trading_platform.metadata\nGROUP BY asset_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "For each user, show their username and the number of unique IP addresses from the peers table where the port is less than 2000."}, {"role": "assistant", "content": "SELECT u.username, COUNT(DISTINCT p.ip_address) AS unique_ip_count\nFROM trading_platform.users u\nJOIN trading_platform.peers p ON u.user_id = p.peer_id\nWHERE p.port < 2000\nGROUP BY u.username;"}, {"role": "user", "content": "This query isn't working because peer_id and user_id don't always match. Could you just show the total number of unique IPs with port < 2000 in the peers table, excluding user data?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT ip_address) AS unique_ip_count\nFROM trading_platform.peers\nWHERE port < 2000;"}, {"role": "user", "content": "Now, for each port number below 2000, show the count of unique IP addresses using that port."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count\nFROM trading_platform.peers\nWHERE port < 2000\nGROUP BY port;"}, {"role": "user", "content": "Actually, only show ports where more than one unique IP address exists."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count\nFROM trading_platform.peers\nWHERE port < 2000\nGROUP BY port\nHAVING COUNT(DISTINCT ip_address) > 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\n", "conversations": [{"role": "user", "content": "I want to see the number of 'buy' and 'sell' orders for each asset, along with the asset_id."}, {"role": "assistant", "content": "SELECT asset_id, order_type, COUNT(*) AS order_count FROM trading_platform.orders GROUP BY asset_id, order_type;"}, {"role": "user", "content": "Can you also show the average price for 'buy' and 'sell' orders for each asset?"}, {"role": "assistant", "content": "SELECT asset_id, order_type, COUNT(*) AS order_count, AVG(price) AS avg_price FROM trading_platform.orders GROUP BY asset_id, order_type;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the usernames of buyers along with the names of assets they have traded."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, a.name AS asset_name\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nJOIN trading_platform.assets a ON t.asset_id = a.asset_id;"}, {"role": "user", "content": "Add the trade quantity for each user and asset pair."}, {"role": "assistant", "content": "SELECT u.username, a.name AS asset_name, SUM(t.quantity) AS total_quantity\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nJOIN trading_platform.assets a ON t.asset_id = a.asset_id\nGROUP BY u.username, a.name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets (\n asset_id character varying(64) NOT NULL, -- unique identifier for the asset\n name character varying(128) NOT NULL, -- name of the asset\n symbol character varying(32) NOT NULL, -- symbol of the asset\n type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)\n PRIMARY KEY (asset_id)\n)\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\n", "conversations": [{"role": "user", "content": "Show the name, symbol, and total quantity traded for each asset."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol;"}, {"role": "user", "content": "Only show assets with a total traded quantity less than 50 and order them by total_quantity_traded ascending."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COALESCE(SUM(t.quantity), 0) < 50\nORDER BY total_quantity_traded ASC;"}, {"role": "user", "content": "Some assets have never been traded and do not appear in the result. Please include those assets as well, with total_quantity_traded as 0."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COALESCE(SUM(t.quantity), 0) < 50 OR SUM(t.quantity) IS NULL\nORDER BY total_quantity_traded ASC;"}, {"role": "user", "content": "I noticed that assets with no trades still appear, but the column name is inconsistent when there are no trades. Can you make sure total_quantity_traded always appears as 0 for such assets and is labeled consistently?"}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COALESCE(SUM(t.quantity), 0) < 50\nORDER BY total_quantity_traded ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all DApps along with the number of metadata entries linked to each, even if the DApp has no linked metadata."}, {"role": "assistant", "content": "SELECT d.name, d.url, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON d.dapp_id = m.asset_id\nGROUP BY d.dapp_id, d.name, d.url;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n", "conversations": [{"role": "user", "content": "Provide a summary for each user, showing their user_id, username, and the total number of orders they have placed overall."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders\nFROM trading_platform.users u\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Now filter to include only users who have 'approved' status in the KYC audit."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders\nFROM trading_platform.users u\nJOIN trading_platform.kyc_audit k ON u.user_id = k.user_id AND k.status = 'approved'\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Also add the sum of quantities from their 'sell' orders."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders, SUM(CASE WHEN o.order_type = 'sell' THEN o.quantity ELSE 0 END) AS total_sell_quantity\nFROM trading_platform.users u\nJOIN trading_platform.kyc_audit k ON u.user_id = k.user_id AND k.status = 'approved'\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Finally, sort by total_sell_quantity descending and limit to the top 5 users."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders, SUM(CASE WHEN o.order_type = 'sell' THEN o.quantity ELSE 0 END) AS total_sell_quantity\nFROM trading_platform.users u\nJOIN trading_platform.kyc_audit k ON u.user_id = k.user_id AND k.status = 'approved'\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username\nORDER BY total_sell_quantity DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List pairs of wallets created on the same day but belonging to different users. Show the wallet IDs, user IDs, and creation dates for both wallets in each pair."}, {"role": "assistant", "content": "SELECT w1.wallet_id AS wallet1_id, w1.user_id AS user1_id, w1.created_at AS wallet1_created_at, w2.wallet_id AS wallet2_id, w2.user_id AS user2_id, w2.created_at AS wallet2_created_at FROM wallets w1 JOIN wallets w2 ON DATE(w1.created_at) = DATE(w2.created_at) AND w1.user_id != w2.user_id AND w1.wallet_id < w2.wallet_id;"}, {"role": "user", "content": "Filter the previous results to only include pairs where both wallet addresses start with '0x'."}, {"role": "assistant", "content": "SELECT w1.wallet_id AS wallet1_id, w1.user_id AS user1_id, w1.created_at AS wallet1_created_at, w2.wallet_id AS wallet2_id, w2.user_id AS user2_id, w2.created_at AS wallet2_created_at FROM wallets w1 JOIN wallets w2 ON DATE(w1.created_at) = DATE(w2.created_at) AND w1.user_id != w2.user_id AND w1.wallet_id < w2.wallet_id WHERE w1.address LIKE '0x%' AND w2.address LIKE '0x%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id text PRIMARY KEY, previous_block_id text, timestamp timestamp, nonce int, merkle_root text, difficulty int )\nCREATE TABLE blockchain.transactions ( transaction_id text PRIMARY KEY, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text )\nCREATE TABLE blockchain.addresses ( address_id text PRIMARY KEY, public_key text, balance numeric )\nCREATE TABLE blockchain.nodes ( node_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE blockchain.users ( user_id text PRIMARY KEY, username text, email text, password_hash text )\nCREATE TABLE blockchain.smart_contracts ( contract_id text PRIMARY KEY, creator_address text, code text, timestamp timestamp )\n", "conversations": [{"role": "user", "content": "List all smart contracts created by addresses that have a balance greater than 1000."}, {"role": "assistant", "content": "SELECT sc.* FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id WHERE a.balance > 1000;"}, {"role": "user", "content": "Now include the username of the user who created these contracts if the creator address is associated with a user."}, {"role": "assistant", "content": "SELECT sc.*, u.username FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id LEFT JOIN blockchain.users u ON a.address_id = u.user_id WHERE a.balance > 1000;"}, {"role": "user", "content": "This query isn't working correctly because the join between addresses and users is wrong. The user_id in users table is not the same as address_id."}, {"role": "assistant", "content": "SELECT sc.*, u.username FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id LEFT JOIN blockchain.users u ON a.public_key = u.email WHERE a.balance > 1000;"}, {"role": "user", "content": "That still doesn't seem right. Let's just show the contracts and their creators' balances without trying to join with users."}, {"role": "assistant", "content": "SELECT sc.contract_id, sc.creator_address, a.balance FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id WHERE a.balance > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.smart_contracts ( contract_id text PRIMARY KEY, creator_address text, code text, timestamp timestamp )\n", "conversations": [{"role": "user", "content": "Show me the earliest created smart contract for each creator address."}, {"role": "assistant", "content": "SELECT DISTINCT ON (creator_address) contract_id, creator_address, code, timestamp FROM blockchain.smart_contracts ORDER BY creator_address, timestamp ASC;"}, {"role": "user", "content": "Now include the total number of contracts each creator has made alongside this information."}, {"role": "assistant", "content": "WITH earliest_contracts AS (SELECT DISTINCT ON (creator_address) contract_id, creator_address, code, timestamp FROM blockchain.smart_contracts ORDER BY creator_address, timestamp ASC) SELECT ec.*, (SELECT COUNT(*) FROM blockchain.smart_contracts sc WHERE sc.creator_address = ec.creator_address) AS total_contracts FROM earliest_contracts ec;"}, {"role": "user", "content": "Filter this to only show creators who have made at least 10 contracts."}, {"role": "assistant", "content": "WITH earliest_contracts AS (SELECT DISTINCT ON (creator_address) contract_id, creator_address, code, timestamp FROM blockchain.smart_contracts ORDER BY creator_address, timestamp ASC) SELECT ec.*, (SELECT COUNT(*) FROM blockchain.smart_contracts sc WHERE sc.creator_address = ec.creator_address) AS total_contracts FROM earliest_contracts ec WHERE (SELECT COUNT(*) FROM blockchain.smart_contracts sc WHERE sc.creator_address = ec.creator_address) >= 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.blocks (\n block_id character varying(64) NOT NULL, -- unique identifier for the block\n previous_block_id character varying(64), -- identifier of the previous block\n timestamp timestamp NOT NULL, -- time when the block was mined\n nonce integer NOT NULL, -- nonce value used in the proof of work\n merkle_root character varying(128) NOT NULL, -- root of the Merkle tree for transactions\n difficulty integer NOT NULL, -- difficulty level of the block\n PRIMARY KEY (block_id)\n)\n", "conversations": [{"role": "user", "content": "Retrieve the block ID, timestamp, current block's difficulty, and the difficulty of the *previous* block for all blocks where the current block's difficulty is strictly greater than the previous block's difficulty."}, {"role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b1.difficulty AS current_difficulty, b2.difficulty AS previous_difficulty FROM blockchain.blocks b1 JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id WHERE b1.difficulty > b2.difficulty;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.nodes ( node_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (node_id) )\n", "conversations": [{"role": "user", "content": "Retrieve all pairs of nodes where one node was last seen before '2023-06-01' and the other after '2023-06-01', and they share the same IP address."}, {"role": "assistant", "content": "SELECT a.node_id AS node_before,\n b.node_id AS node_after,\n a.ip_address\nFROM blockchain.nodes a\nJOIN blockchain.nodes b\n ON a.ip_address = b.ip_address\nWHERE a.last_seen < '2023-06-01'\n AND b.last_seen > '2023-06-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text )\n", "conversations": [{"role": "user", "content": "List the names of services that have been scheduled at accessible service locations."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN government_services.appointments AS T2 ON T1.service_id = T2.service_id JOIN government_services.service_locations AS T3 ON T2.location_id = T3.location_id WHERE T3.is_accessible = TRUE"}, {"role": "user", "content": "Now, only include services from agencies with 'State' jurisdiction level."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN government_services.appointments AS T2 ON T1.service_id = T2.service_id JOIN government_services.service_locations AS T3 ON T2.location_id = T3.location_id JOIN government_services.agencies AS T4 ON T1.agency_id = T4.agency_id WHERE T3.is_accessible = TRUE AND T4.jurisdiction_level = 'State'"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "How many documents are in each verification_status?"}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nGROUP BY verification_status;"}, {"role": "user", "content": "Only include statuses with more than 100 documents."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nGROUP BY verification_status\nHAVING COUNT(*) > 100;"}, {"role": "user", "content": "Order the results by document_count in descending order."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nGROUP BY verification_status\nHAVING COUNT(*) > 100\nORDER BY document_count DESC;"}, {"role": "user", "content": "Also exclude documents where expiry_date is before today."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nWHERE expiry_date >= CURRENT_DATE\nGROUP BY verification_status\nHAVING COUNT(*) > 100\nORDER BY document_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "List application reference numbers and the total amount paid for each application that has at least one completed payment."}, {"role": "assistant", "content": "SELECT a.reference_number, SUM(p.amount) AS total_paid FROM government_services.applications AS a JOIN government_services.payments AS p ON a.application_id = p.application_id WHERE p.status = 'Completed' GROUP BY a.reference_number;"}, {"role": "user", "content": "Also include the citizen's first and last name who submitted the application."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, a.reference_number, SUM(p.amount) AS total_paid FROM government_services.applications AS a JOIN government_services.payments AS p ON a.application_id = p.application_id JOIN government_services.citizens AS c ON a.citizen_id = c.citizen_id WHERE p.status = 'Completed' GROUP BY c.first_name, c.last_name, a.reference_number;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "How many documents were uploaded in the month of October 2023?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM government_services.documents WHERE upload_timestamp >= '2023-10-01 00:00:00' AND upload_timestamp < '2023-11-01 00:00:00';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\n", "conversations": [{"role": "user", "content": "Can you list the names of agencies that do not have a parent agency assigned, ordered by their established date?"}, {"role": "assistant", "content": "SELECT agency_id, agency_name, established_date\nFROM government_services.agencies\nWHERE parent_agency_id IS NULL\nORDER BY established_date;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "For each employee, find their first and last name along with the number of applications they've been assigned. Only include employees with at least 5 assigned applications."}, {"role": "assistant", "content": "SELECT e.first_name,\n e.last_name,\n COUNT(a.application_id) AS assigned_count\nFROM government_services.employees e\nJOIN government_services.applications a ON e.employee_id = a.assigned_employee_id\nGROUP BY e.first_name, e.last_name\nHAVING COUNT(a.application_id) >= 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "How many documents have a file reference assigned?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM government_services.documents WHERE file_reference IS NOT NULL AND file_reference <> '';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "List the appointment ID, the scheduled start time, and the name of the service location for all appointments scheduled between '2024-01-01' and '2024-12-31'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.scheduled_start_time, T2.location_name FROM government_services.appointments AS T1 INNER JOIN government_services.service_locations AS T2 ON T1.location_id = T2.location_id WHERE T1.scheduled_start_time >= '2024-01-01' AND T1.scheduled_start_time < '2025-01-01';"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\n", "conversations": [{"role": "user", "content": "How many payments have been made using each payment_method, and what is the total amount for each method?"}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nGROUP BY payment_method;"}, {"role": "user", "content": "Can you filter to only include methods where the total_amount exceeds 1000?"}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nGROUP BY payment_method\nHAVING SUM(amount) > 1000;"}, {"role": "user", "content": "Also exclude any payments with status other than 'Completed'."}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nWHERE status = 'Completed'\nGROUP BY payment_method\nHAVING SUM(amount) > 1000;"}, {"role": "user", "content": "Order the results by total_amount descending and limit to the top 5 payment methods."}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nWHERE status = 'Completed'\nGROUP BY payment_method\nHAVING SUM(amount) > 1000\nORDER BY total_amount DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Find all pairs of overlapping reservations for the same room. Show the two reservation IDs, room_id, and both reservations' check-in and check-out dates."}, {"role": "assistant", "content": "SELECT r1.reservation_id AS reservation1_id, r2.reservation_id AS reservation2_id, r1.room_id, r1.check_in_date AS reservation1_check_in, r1.check_out_date AS reservation1_check_out, r2.check_in_date AS reservation2_check_in, r2.check_out_date AS reservation2_check_out FROM hospitality_technology.reservations r1 JOIN hospitality_technology.reservations r2 ON r1.room_id = r2.room_id AND r1.reservation_id < r2.reservation_id AND r1.check_in_date < r2.check_out_date AND r2.check_in_date < r1.check_out_date;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n", "conversations": [{"role": "user", "content": "List all patients who have both primary and non-primary insurance plans, showing their full names and the count of each type of plan."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, SUM(CASE WHEN pi.is_primary = true THEN 1 ELSE 0 END) AS primary_plans, SUM(CASE WHEN pi.is_primary = false THEN 1 ELSE 0 END) AS non_primary_plans FROM healthcare.patients p JOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id GROUP BY p.patient_id, p.first_name, p.last_name HAVING SUM(CASE WHEN pi.is_primary = true THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN pi.is_primary = false THEN 1 ELSE 0 END) > 0;"}, {"role": "user", "content": "Actually, I only need patients who have more than one non-primary insurance plan."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, SUM(CASE WHEN pi.is_primary = true THEN 1 ELSE 0 END) AS primary_plans, SUM(CASE WHEN pi.is_primary = false THEN 1 ELSE 0 END) AS non_primary_plans FROM healthcare.patients p JOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id GROUP BY p.patient_id, p.first_name, p.last_name HAVING SUM(CASE WHEN pi.is_primary = false THEN 1 ELSE 0 END) > 1;"}, {"role": "user", "content": "Can you also include the insurance provider names for their non-primary plans?"}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, ip.insurance_provider, COUNT(pi.plan_id) AS non_primary_plans_count FROM healthcare.patients p JOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary = false GROUP BY p.patient_id, p.first_name, p.last_name, ip.insurance_provider HAVING COUNT(pi.plan_id) > 1;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\nCREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find the wallet address, user ID, and the contract address of any contract where that wallet is listed as the deployer."}, {"role": "assistant", "content": "SELECT w.address AS wallet_address, w.user_id, c.address AS contract_address\nFROM web3.wallets w\nJOIN web3.contracts c ON w.address = c.deployer_address;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations (\n reservation_id character varying(64) NOT NULL, -- unique identifier for the booking\n property_id character varying(64) NOT NULL, -- FK to properties table\n guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)\n room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)\n room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)\n check_in_date date NOT NULL, -- scheduled check-in date\n check_out_date date NOT NULL, -- scheduled check-out date\n actual_check_in_ts timestamp with time zone, -- actual check-in time\n actual_check_out_ts timestamp with time zone, -- actual check-out time\n num_adults integer NOT NULL, -- number of adults\n num_children integer DEFAULT 0, -- number of children\n status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow\n booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn\n rate_plan_id character varying(64), -- FK to rate_plans table (optional)\n total_amount numeric(12, 2), -- estimated or final total cost\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n special_requests text, -- specific guest requests for this booking\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (reservation_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment transaction\n reservation_id character varying(64), -- FK to reservations (if payment is for a stay)\n guest_id character varying(64) NOT NULL, -- FK to guests (who paid)\n bill_id character varying(64), -- FK to bills/invoices this payment applies to\n amount numeric(12,2) NOT NULL, -- amount of the payment\n currency_code character varying(3) NOT NULL, -- ISO currency code (e.g., USD, EUR)\n payment_method character varying(50) NOT NULL, -- e.g., CreditCard, Cash, BankTransfer, Points, Voucher\n card_type character varying(50), -- e.g., Visa, MasterCard, Amex (if CC)\n card_last_four character varying(4), -- last 4 digits of CC (if CC)\n transaction_ref character varying(128), -- reference ID from payment gateway or processor\n payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the payment occurred\n status character varying(50) NOT NULL, -- e.g., Pending, Succeeded, Failed, Refunded, Disputed\n staff_id_processed character varying(64), -- FK to staff (who processed the payment)\n notes text, -- notes about the payment\n PRIMARY KEY (payment_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.reviews (\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 reservations made in the last 6 months, showing the reservation ID, guest ID, and status."}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, status FROM hospitality_technology.reservations WHERE created_at >= current_date - interval '6 months';"}, {"role": "user", "content": "Actually, I only want reservations where the check-in date is in the future."}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, status FROM hospitality_technology.reservations WHERE created_at >= current_date - interval '6 months' AND check_in_date > current_date;"}, {"role": "user", "content": "For these future reservations created recently, can you also show the property name and the room type name?"}, {"role": "assistant", "content": "SELECT T1.reservation_id, T1.guest_id, T1.status, T2.property_name, T3.type_name FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.room_types AS T3 ON T1.room_type_id = T3.room_type_id WHERE T1.created_at >= current_date - interval '6 months' AND T1.check_in_date > current_date;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )\nCREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) )\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.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.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id 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) )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "Find users with push_notifications_enabled set to false who have unread notifications. Show their username and the count of unread notifications."}, {"role": "assistant", "content": "SELECT u.username, COUNT(n.notification_id) AS unread_count FROM social_media.user_settings s JOIN social_media.notifications n ON s.user_id = n.recipient_user_id AND n.read_at IS NULL JOIN social_media.users u ON u.user_id = s.user_id WHERE s.push_notifications_enabled = FALSE GROUP BY u.username;"}, {"role": "user", "content": "Also include their email and the timestamp of their latest unread notification."}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(n.notification_id) AS unread_count, MAX(n.created_at) AS last_unread_at FROM social_media.user_settings s JOIN social_media.notifications n ON s.user_id = n.recipient_user_id AND n.read_at IS NULL JOIN social_media.users u ON u.user_id = s.user_id WHERE s.push_notifications_enabled = FALSE GROUP BY u.username, u.email;"}, {"role": "user", "content": "Now only show users with more than 3 unread notifications and sort by unread_count descending."}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(n.notification_id) AS unread_count, MAX(n.created_at) AS last_unread_at FROM social_media.user_settings s JOIN social_media.notifications n ON s.user_id = n.recipient_user_id AND n.read_at IS NULL JOIN social_media.users u ON u.user_id = s.user_id WHERE s.push_notifications_enabled = FALSE GROUP BY u.username, u.email HAVING COUNT(n.notification_id) > 3 ORDER BY unread_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n", "conversations": [{"role": "user", "content": "Find the claim ID and the total number of documents associated with each claim ID that has more than 10 documents."}, {"role": "assistant", "content": "SELECT claim_id, COUNT(*) FROM insurance.claim_documents GROUP BY claim_id HAVING COUNT(*) > 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "List the first name, last name, prescription ID, diagnosis code, and diagnosis description for patients who have both an ongoing prescription and an active chronic diagnosis."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name, T2.prescription_id, T3.diagnosis_code, T3.description FROM healthcare.patients AS T1 JOIN healthcare.prescriptions AS T2 ON T1.patient_id = T2.patient_id JOIN healthcare.diagnoses AS T3 ON T1.patient_id = T3.patient_id WHERE (T2.end_date IS NULL OR T2.end_date > CURRENT_DATE) AND T3.is_chronic IS TRUE AND T3.status = 'Active';"}, {"role": "user", "content": "Refine the results to include only those cases where the prescription started within 30 days before or on the diagnosis date."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name, T2.prescription_id, T3.diagnosis_code, T3.description FROM healthcare.patients AS T1 JOIN healthcare.prescriptions AS T2 ON T1.patient_id = T2.patient_id JOIN healthcare.diagnoses AS T3 ON T1.patient_id = T3.patient_id WHERE (T2.end_date IS NULL OR T2.end_date > CURRENT_DATE) AND T3.is_chronic IS TRUE AND T3.status = 'Active' AND T2.start_date BETWEEN T3.diagnosis_date - INTERVAL '30 days' AND T3.diagnosis_date;"}, {"role": "user", "content": "Add the full names of the doctor who wrote the prescription and the doctor who made the diagnosis to the results."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name, T2.prescription_id, T3.diagnosis_code, T3.description, T4.first_name AS prescribing_doctor_first_name, T4.last_name AS prescribing_doctor_last_name, T5.first_name AS diagnosing_doctor_first_name, T5.last_name AS diagnosing_doctor_last_name FROM healthcare.patients AS T1 JOIN healthcare.prescriptions AS T2 ON T1.patient_id = T2.patient_id JOIN healthcare.diagnoses AS T3 ON T1.patient_id = T3.patient_id JOIN healthcare.doctors AS T4 ON T2.doctor_id = T4.doctor_id JOIN healthcare.doctors AS T5 ON T3.doctor_id = T5.doctor_id WHERE (T2.end_date IS NULL OR T2.end_date > CURRENT_DATE) AND T3.is_chronic IS TRUE AND T3.status = 'Active' AND T2.start_date BETWEEN T3.diagnosis_date - INTERVAL '30 days' AND T3.diagnosis_date;"}, {"role": "user", "content": "Filter the results to only include diagnoses with a code type of 'ICD-9' and where either the prescribing or diagnosing doctor has a specialty in 'Cardiology'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name, T2.prescription_id, T3.diagnosis_code, T3.description, T4.first_name AS prescribing_doctor_first_name, T4.last_name AS prescribing_doctor_last_name, T5.first_name AS diagnosing_doctor_first_name, T5.last_name AS diagnosing_doctor_last_name FROM healthcare.patients AS T1 JOIN healthcare.prescriptions AS T2 ON T1.patient_id = T2.patient_id JOIN healthcare.diagnoses AS T3 ON T1.patient_id = T3.patient_id JOIN healthcare.doctors AS T4 ON T2.doctor_id = T4.doctor_id JOIN healthcare.doctors AS T5 ON T3.doctor_id = T5.doctor_id WHERE (T2.end_date IS NULL OR T2.end_date > CURRENT_DATE) AND T3.is_chronic IS TRUE AND T3.status = 'Active' AND T2.start_date BETWEEN T3.diagnosis_date - INTERVAL '30 days' AND T3.diagnosis_date AND T3.code_type = 'ICD-9' AND (T4.specialty = 'Cardiology' OR T5.specialty = 'Cardiology');"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\n", "conversations": [{"role": "user", "content": "I need a list of unique company names and the number of clients in each company."}, {"role": "assistant", "content": "SELECT company_name, COUNT(*) AS client_count\nFROM legal_services.clients\nWHERE company_name IS NOT NULL\nGROUP BY company_name;"}, {"role": "user", "content": "Only include companies where there are at least 2 clients."}, {"role": "assistant", "content": "SELECT company_name, COUNT(*) AS client_count\nFROM legal_services.clients\nWHERE company_name IS NOT NULL\nGROUP BY company_name\nHAVING COUNT(*) >= 2;"}, {"role": "user", "content": "Also, show the email addresses of the clients in those companies."}, {"role": "assistant", "content": "SELECT c.company_name, c.email\nFROM legal_services.clients c\nWHERE c.company_name IN (\n SELECT company_name\n FROM legal_services.clients\n WHERE company_name IS NOT NULL\n GROUP BY company_name\n HAVING COUNT(*) >= 2\n)\nORDER BY c.company_name, c.email;"}, {"role": "user", "content": "Only show companies whose name contains the word 'Group'."}, {"role": "assistant", "content": "SELECT c.company_name, c.email\nFROM legal_services.clients c\nWHERE c.company_name IN (\n SELECT company_name\n FROM legal_services.clients\n WHERE company_name IS NOT NULL AND company_name ILIKE '%Group%'\n GROUP BY company_name\n HAVING COUNT(*) >= 2\n)\nORDER BY c.company_name, c.email;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "I want the number of peers per port, but only ports with more than 5 peers. List port and peer_count."}, {"role": "assistant", "content": "SELECT port, COUNT(*) AS peer_count\nFROM trading_platform.peers\nGROUP BY port\nHAVING COUNT(*) > 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 in-progress trips with their current locations (origin_location_id) and destinations, along with the scheduled vs actual departure time difference in minutes."}, {"role": "assistant", "content": "SELECT trip_id, origin_location_id, destination_location_id, EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 AS departure_delay_minutes FROM transportation.trips WHERE status = 'In Progress';"}, {"role": "user", "content": "Can you also include the vehicle_id and driver_id, and order by the departure delay in descending order?"}, {"role": "assistant", "content": "SELECT trip_id, vehicle_id, driver_id, origin_location_id, destination_location_id, EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 AS departure_delay_minutes FROM transportation.trips WHERE status = 'In Progress' ORDER BY departure_delay_minutes DESC;"}, {"role": "user", "content": "Now filter to only show trips that have been delayed by more than 30 minutes."}, {"role": "assistant", "content": "SELECT trip_id, vehicle_id, driver_id, origin_location_id, destination_location_id, EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 AS departure_delay_minutes FROM transportation.trips WHERE status = 'In Progress' AND EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 > 30 ORDER BY departure_delay_minutes DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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)\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all peers with their IP addresses who have not been seen in the last 7 days."}, {"role": "assistant", "content": "SELECT peer_id, ip_address, port, last_seen\nFROM trading_platform.peers\nWHERE last_seen < NOW() - INTERVAL '7 days';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\n", "conversations": [{"role": "user", "content": "Show me the first and last names of citizens along with their dates of birth and contact emails for all citizens who registered after January 1, 2023."}, {"role": "assistant", "content": "SELECT first_name, last_name, date_of_birth, contact_email FROM government_services.citizens WHERE registration_date > '2023-01-01';"}, {"role": "user", "content": "Only include citizens whose accounts are verified."}, {"role": "assistant", "content": "SELECT first_name, last_name, date_of_birth, contact_email FROM government_services.citizens WHERE registration_date > '2023-01-01' AND is_verified = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "How many messages in total have been sent that do not contain any media attachment?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS non_media_message_count\nFROM social_media.messages\nWHERE media_url IS NULL OR media_url = '';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (doctor_id) )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "Show a list of diagnoses along with the chief complaint noted in the corresponding medical record. Display diagnosis description, diagnosis date, and the chief complaint."}, {"role": "assistant", "content": "SELECT T1.description, T1.diagnosis_date, T2.chief_complaint FROM healthcare.diagnoses AS T1 JOIN healthcare.medical_records AS T2 ON T1.record_id = T2.record_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\n", "conversations": [{"role": "user", "content": "Show the earliest and latest timestamp recorded in the logs table."}, {"role": "assistant", "content": "SELECT MIN(logged_at), MAX(logged_at) FROM trading_platform.logs;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.nodes ( node_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (node_id) )\n", "conversations": [{"role": "user", "content": "List each port along with the count of distinct IP addresses observed on that port."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count FROM blockchain.nodes GROUP BY port;"}, {"role": "user", "content": "Only include ports that have more than 3 unique IP addresses."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count FROM blockchain.nodes GROUP BY port HAVING COUNT(DISTINCT ip_address) > 3;"}, {"role": "user", "content": "Also include the latest last_seen timestamp for each of these ports."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count, MAX(last_seen) AS last_seen_latest FROM blockchain.nodes GROUP BY port HAVING COUNT(DISTINCT ip_address) > 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "Give me a list of employees (first and last name) along with the count of appointments they have scheduled."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(a.appointment_id) AS appointment_count\nFROM government_services.employees e\nLEFT JOIN government_services.appointments a ON e.employee_id = a.employee_id\nGROUP BY e.employee_id, e.first_name, e.last_name;"}, {"role": "user", "content": "Only show employees who have scheduled at least 5 appointments."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(a.appointment_id) AS appointment_count\nFROM government_services.employees e\nLEFT JOIN government_services.appointments a ON e.employee_id = a.employee_id\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(a.appointment_id) >= 5;"}, {"role": "user", "content": "Can you also show the average duration of their appointments in minutes?"}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(a.appointment_id) AS appointment_count,\n AVG(EXTRACT(EPOCH FROM (a.scheduled_end_time - a.scheduled_start_time)) / 60) AS avg_duration_minutes\nFROM government_services.employees e\nLEFT JOIN government_services.appointments a ON e.employee_id = a.employee_id\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(a.appointment_id) >= 5;"}, {"role": "user", "content": "I got an error because some appointments have missing end times. Can you fix the query to only compute the average using appointments where both start and end times are present?"}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(a.appointment_id) AS appointment_count,\n AVG(EXTRACT(EPOCH FROM (a.scheduled_end_time - a.scheduled_start_time)) / 60) AS avg_duration_minutes\nFROM government_services.employees e\nLEFT JOIN government_services.appointments a ON e.employee_id = a.employee_id AND a.scheduled_start_time IS NOT NULL AND a.scheduled_end_time IS NOT NULL\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(a.appointment_id) >= 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 trend rank in the 'NFT' narrative, along with their price and 24-hour trading volume."}, {"role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume FROM token_basic_info WHERE narrative = 'NFT' ORDER BY trend_rank ASC LIMIT 3;"}, {"role": "user", "content": "Can you also include their 1-hour and 7-day price change percentages?"}, {"role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume, price_change_percentage_1h, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' ORDER BY trend_rank ASC LIMIT 3;"}, {"role": "user", "content": "Actually, I only want tokens with positive price changes in both time frames."}, {"role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume, price_change_percentage_1h, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' AND price_change_percentage_1h > 0 AND price_change_percentage_7d > 0 ORDER BY trend_rank ASC LIMIT 3;"}, {"role": "user", "content": "Now order the results by 24-hour trading volume instead of trend rank."}, {"role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume, price_change_percentage_1h, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' AND price_change_percentage_1h > 0 AND price_change_percentage_7d > 0 ORDER BY total_volume::numeric DESC LIMIT 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n// PUT /schedules\n{\n \"mappings\": {\n \"properties\": {\n \"schedule_id\": { \"type\": \"keyword\" },\n \"train_id\": { \"type\": \"keyword\" }, // References trains index\n \"route_id\": { \"type\": \"keyword\" }, // References routes index\n \"departure_datetime\": { \"type\": \"date\" }, // ISO 8601 format recommended\n \"arrival_datetime\": { \"type\": \"date\" },\n \"status\": { \"type\": \"keyword\" },\n \"notes\": { \"type\": \"text\" }\n }\n }\n}\n// PUT /passengers\n{\n \"mappings\": {\n \"properties\": {\n \"passenger_id\": { \"type\": \"keyword\" },\n \"first_name\": { \n \"type\": \"text\", \n \"fields\": { \"keyword\": { \"type\": \"keyword\", \"ignore_above\": 100 } }\n },\n \"last_name\": { \n \"type\": \"text\", \n \"fields\": { \"keyword\": { \"type\": \"keyword\", \"ignore_above\": 100 } }\n },\n \"email\": { \"type\": \"keyword\" }, // Often used for exact matches\n \"phone_number\": { \"type\": \"keyword\" },\n \"date_of_birth\": { \"type\": \"date\", \"format\": \"yyyy-MM-dd\" },\n \"loyalty_program_id\": { \"type\": \"keyword\" },\n \"created_at\": { \"type\": \"date\" }\n }\n }\n}\n", "conversations": [{"role": "user", "content": "\u80fd\u5426\u5e2e\u6211\u67e5\u8be2\u7279\u5b9a\u8def\u7ebf(route_id \u4e3a 'RT001')\u7684\u6240\u6709\u884c\u7a0b\u4fe1\u606f\uff0c\u5e76\u5173\u8054\u5230\u4e58\u5ba2\u7684\u8054\u7cfb\u65b9\u5f0f\uff1f"}, {"role": "assistant", "content": "SELECT s.schedule_id, s.train_id, s.route_id, s.departure_datetime, s.arrival_datetime, s.status, p.passenger_id, p.first_name, p.last_name, p.phone_number, p.email\nFROM schedules s\nLEFT JOIN passengers p ON s.schedule_id = (SELECT schedule_id FROM bookings WHERE passenger_id = p.passenger_id)\nWHERE s.route_id = 'RT001';"}, {"role": "user", "content": "\u80fd\u5426\u53ea\u663e\u793a\u72b6\u6001\u4e3a\u2018On Time\u2019\u7684\u884c\u7a0b\uff0c\u5e76\u6309\u51fa\u53d1\u65f6\u95f4\u5347\u5e8f\u6392\u5217\uff1f"}, {"role": "assistant", "content": "SELECT s.schedule_id, s.train_id, s.route_id, s.departure_datetime, s.arrival_datetime, s.status, p.passenger_id, p.first_name, p.last_name, p.phone_number, p.email\nFROM schedules s\nLEFT JOIN passengers p ON s.schedule_id = (SELECT schedule_id FROM bookings WHERE passenger_id = p.passenger_id)\nWHERE s.route_id = 'RT001' AND s.status = 'On Time'\nORDER BY s.departure_datetime ASC;"}, {"role": "user", "content": "\u5982\u679c\u4e58\u5ba2\u4fe1\u606f\u4e3a\u7a7a\uff0c\u80fd\u5426\u4ecd\u7136\u663e\u793a\u884c\u7a0b\u4fe1\u606f\uff0c\u5e76\u9650\u5236\u7ed3\u679c\u524d10\u6761\uff1f"}, {"role": "assistant", "content": "SELECT s.schedule_id, s.train_id, s.route_id, s.departure_datetime, s.arrival_datetime, s.status, p.passenger_id, p.first_name, p.last_name, p.phone_number, p.email\nFROM schedules s\nLEFT JOIN passengers p ON s.schedule_id = (SELECT schedule_id FROM bookings WHERE passenger_id = p.passenger_id)\nWHERE s.route_id = 'RT001' AND s.status = 'On Time'\nORDER BY s.departure_datetime ASC\nLIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.insurance_products (\n product_id character varying(64) NOT NULL, -- unique identifier for the insurance product\n product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')\n product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'\n description text, -- detailed description of the product\n base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments\n coverage_details text, -- details about what is covered (could be JSON or structured text)\n underwriting_rules text, -- rules used for assessing risk and eligibility\n is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at timestamp,\n PRIMARY KEY (product_id)\n)\n", "conversations": [{"role": "user", "content": "List all insurance products with a base premium greater than 1000 and less than 5000. Show the product name, product type, and base premium."}, {"role": "assistant", "content": "SELECT product_name, product_type, base_premium FROM insurance.insurance_products WHERE base_premium > 1000 AND base_premium < 5000;"}, {"role": "user", "content": "Could you also include products that are not currently active in the results?"}, {"role": "assistant", "content": "SELECT product_name, product_type, base_premium FROM insurance.insurance_products WHERE (base_premium > 1000 AND base_premium < 5000) OR is_active = FALSE;"}, {"role": "user", "content": "Order the results by product name alphabetically."}, {"role": "assistant", "content": "SELECT product_name, product_type, base_premium FROM insurance.insurance_products WHERE (base_premium > 1000 AND base_premium < 5000) OR is_active = FALSE ORDER BY product_name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\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": "How many patients have at least one medical record associated with them?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT patient_id) FROM healthcare.medical_records;"}, {"role": "user", "content": "Now, can you show me the count of patients who do *not* have any medical records?"}, {"role": "assistant", "content": "SELECT COUNT(p.patient_id) FROM healthcare.patients p LEFT JOIN healthcare.medical_records mr ON p.patient_id = mr.patient_id WHERE mr.record_id IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "Show me the review_id, review_date, and comment for all non-public reviews along with the guest's first and last name."}, {"role": "assistant", "content": "SELECT r.review_id, r.review_date, r.comment, g.first_name, g.last_name\nFROM hospitality_technology.reviews r\nJOIN hospitality_technology.guests g ON r.guest_id = g.guest_id\nWHERE r.is_public = false;"}, {"role": "user", "content": "Actually, only include those reviews where the staff has responded and include the staff member's full name and response_date."}, {"role": "assistant", "content": "SELECT r.review_id, r.review_date, r.comment, g.first_name, g.last_name, s.first_name AS resp_first_name, s.last_name AS resp_last_name, r.response_date\nFROM hospitality_technology.reviews r\nJOIN hospitality_technology.guests g ON r.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON r.response_staff_id = s.staff_id\nWHERE r.is_public = false\n AND r.staff_response IS NOT NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List the appointment ID, start time, and the case number for all appointments that are linked to a case."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.start_time, T2.case_number FROM legal_services.appointments AS T1 JOIN legal_services.cases AS T2 ON T1.case_id = T2.case_id"}, {"role": "user", "content": "Refine this to only show appointments with status 'completed' associated with cases with status 'Closed'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.start_time, T2.case_number FROM legal_services.appointments AS T1 JOIN legal_services.cases AS T2 ON T1.case_id = T2.case_id WHERE T1.status = 'completed' AND T2.status = 'Closed'"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id.text, national_id_number.text, first_name.text, last_name.text, date_of_birth.date, gender.text, primary_address.text, contact_email.text, contact_phone.text, registration_date.timestamp, is_verified.boolean )\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\nCREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp )\nCREATE TABLE government_services.employees ( employee_id.text, agency_id.text, first_name.text, last_name.text, job_title.text, department.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, access_level.text, manager_employee_id.text )\nCREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text )\n", "conversations": [{"role": "user", "content": "For each employee, show their first and last name and the number of documents they have verified."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(d.document_id) AS verified_documents_count\nFROM government_services.employees e\nJOIN government_services.documents d ON e.employee_id = d.verified_by_employee_id\nGROUP BY e.employee_id, e.first_name, e.last_name;"}, {"role": "user", "content": "Only include employees who have verified more than 2 documents."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(d.document_id) AS verified_documents_count\nFROM government_services.employees e\nJOIN government_services.documents d ON e.employee_id = d.verified_by_employee_id\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(d.document_id) > 2;"}, {"role": "user", "content": "Also, show the latest verification date for documents each employee has verified."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(d.document_id) AS verified_documents_count, MAX(d.verification_timestamp) AS latest_verification\nFROM government_services.employees e\nJOIN government_services.documents d ON e.employee_id = d.verified_by_employee_id\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(d.document_id) > 2;"}, {"role": "user", "content": "Now, include the agency name each employee belongs to."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, a.agency_name, COUNT(d.document_id) AS verified_documents_count, MAX(d.verification_timestamp) AS latest_verification\nFROM government_services.employees e\nJOIN government_services.documents d ON e.employee_id = d.verified_by_employee_id\nJOIN government_services.agencies a ON e.agency_id = a.agency_id\nGROUP BY e.employee_id, e.first_name, e.last_name, a.agency_name\nHAVING COUNT(d.document_id) > 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.locations ( location_id 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.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 the route number, description, and the name of both the origin and destination locations for all routes where the origin and destination are in different countries."}, {"role": "assistant", "content": "SELECT r.route_number, r.description, l1.name AS origin_name, l2.name AS destination_name\nFROM transportation.routes r\nJOIN transportation.locations l1 ON r.origin_location_id = l1.location_id\nJOIN transportation.locations l2 ON r.destination_location_id = l2.location_id\nWHERE l1.country <> l2.country;"}, {"role": "user", "content": "Add to this the type of each route, and only include routes where the estimated duration exceeds 180 minutes."}, {"role": "assistant", "content": "SELECT r.route_number, r.description, r.type, l1.name AS origin_name, l2.name AS destination_name\nFROM transportation.routes r\nJOIN transportation.locations l1 ON r.origin_location_id = l1.location_id\nJOIN transportation.locations l2 ON r.destination_location_id = l2.location_id\nWHERE l1.country <> l2.country\n AND r.estimated_duration_minutes > 180;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id text, first_name text, last_name text, bar_number text, firm_id text, email text, phone text, specialization text, hire_date timestamp, is_partner boolean )\n", "conversations": [{"role": "user", "content": "List all lawyers along with the full name of another lawyer from the same firm."}, {"role": "assistant", "content": "SELECT a.lawyer_id,\n CONCAT(a.first_name, ' ', a.last_name) AS full_name,\n CONCAT(b.first_name, ' ', b.last_name) AS colleague_full_name\nFROM legal_services.lawyers a\nJOIN legal_services.lawyers b\n ON a.firm_id = b.firm_id\n AND a.lawyer_id <> b.lawyer_id;"}, {"role": "user", "content": "Actually, only include pairs where both lawyers were hired in the same year."}, {"role": "assistant", "content": "SELECT a.lawyer_id,\n CONCAT(a.first_name, ' ', a.last_name) AS full_name,\n CONCAT(b.first_name, ' ', b.last_name) AS colleague_full_name\nFROM legal_services.lawyers a\nJOIN legal_services.lawyers b\n ON a.firm_id = b.firm_id\n AND a.lawyer_id <> b.lawyer_id\n AND EXTRACT(YEAR FROM a.hire_date) = EXTRACT(YEAR FROM b.hire_date);"}, {"role": "user", "content": "Also, make sure the specialization matches for both lawyers."}, {"role": "assistant", "content": "SELECT a.lawyer_id,\n CONCAT(a.first_name, ' ', a.last_name) AS full_name,\n CONCAT(b.first_name, ' ', b.last_name) AS colleague_full_name\nFROM legal_services.lawyers a\nJOIN legal_services.lawyers b\n ON a.firm_id = b.firm_id\n AND a.lawyer_id <> b.lawyer_id\n AND EXTRACT(YEAR FROM a.hire_date) = EXTRACT(YEAR FROM b.hire_date)\n AND a.specialization = b.specialization;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.reservations ( reservation_id.text, property_id.text, guest_id.text, room_id.text, room_type_id.text, check_in_date.date, check_out_date.date, actual_check_in_ts.timestamp, actual_check_out_ts.timestamp, num_adults.integer, num_children.integer, status.text, booking_source.text, rate_plan_id.text, total_amount.numeric, amount_paid.numeric, special_requests.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "Show me staff members who were hired after the property they work at was created. List their first name, last name, hire date, the property name, and the property creation date."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.hire_date, T2.property_name, T2.created_at FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.hire_date > T2.created_at ORDER BY T1.hire_date;"}, {"role": "user", "content": "Filter this list to only include staff members whose position is 'Concierge' or 'Guest Services' and order by hire date ascending."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.hire_date, T2.property_name, T2.created_at FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.hire_date > T2.created_at AND T1.position IN ('Concierge', 'Guest Services') ORDER BY T1.hire_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\n", "conversations": [{"role": "user", "content": "Show me all active electric vehicles along with their make, model, and license plate, ordered by acquisition date with the newest first."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, license_plate, acquisition_date FROM transportation.vehicles WHERE status = 'active' AND fuel_type = 'electric' ORDER BY acquisition_date DESC;"}, {"role": "user", "content": "Now include the depot_id for these vehicles and filter to only show vehicles acquired in the last 2 years."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, license_plate, acquisition_date, depot_id FROM transportation.vehicles WHERE status = 'active' AND fuel_type = 'electric' AND acquisition_date >= CURRENT_DATE - INTERVAL '2 years' ORDER BY acquisition_date DESC;"}, {"role": "user", "content": "Can you also include the vehicle's capacity and order the results by capacity in descending order?"}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, license_plate, acquisition_date, depot_id, capacity FROM transportation.vehicles WHERE status = 'active' AND fuel_type = 'electric' AND acquisition_date >= CURRENT_DATE - INTERVAL '2 years' ORDER BY capacity DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.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": "For each user, can you list all their wallet addresses and the creation timestamps of those wallets?"}, {"role": "assistant", "content": "SELECT user_id, address, created_at FROM web3.wallets ORDER BY user_id, created_at;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL DEFAULT 'USA', phone_number character varying(30), email character varying(128) UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, status character varying(20) NOT NULL DEFAULT 'Active', PRIMARY KEY (customer_id) )\n", "conversations": [{"role": "user", "content": "Show me all customers whose last name starts with 'M' and who were created in the system after July 1, 2022."}, {"role": "assistant", "content": "SELECT customer_id, first_name, last_name, email, created_at\nFROM insurance.customers\nWHERE last_name LIKE 'M%' AND created_at > '2022-07-01';"}, {"role": "user", "content": "Please also add their city and zip code to the results."}, {"role": "assistant", "content": "SELECT customer_id, first_name, last_name, email, city, zip_code, created_at\nFROM insurance.customers\nWHERE last_name LIKE 'M%' AND created_at > '2022-07-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id.text, property_id.text, guest_id.text, room_id.text, room_type_id.text, check_in_date.date, check_out_date.date, actual_check_in_ts.timestamp, actual_check_out_ts.timestamp, num_adults.integer, num_children.integer, status.text, booking_source.text, rate_plan_id.text, total_amount.numeric, amount_paid.numeric, special_requests.text, created_at.timestamp, updated_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me each guest's reservation count and average stay length in days."}, {"role": "assistant", "content": "SELECT guest_id,\n COUNT(*) AS reservation_count,\n AVG(check_out_date - check_in_date) AS avg_stay_days\nFROM hospitality_technology.reservations\nGROUP BY guest_id;"}, {"role": "user", "content": "Filter to only include guests with more than 3 reservations."}, {"role": "assistant", "content": "SELECT guest_id,\n COUNT(*) AS reservation_count,\n AVG(check_out_date - check_in_date) AS avg_stay_days\nFROM hospitality_technology.reservations\nGROUP BY guest_id\nHAVING COUNT(*) > 3;"}, {"role": "user", "content": "Also join this with a subquery to display the total amount paid per guest."}, {"role": "assistant", "content": "SELECT s.guest_id,\n s.reservation_count,\n s.avg_stay_days,\n p.total_amount_paid\nFROM (\n SELECT guest_id,\n COUNT(*) AS reservation_count,\n AVG(check_out_date - check_in_date) AS avg_stay_days\n FROM hospitality_technology.reservations\n GROUP BY guest_id\n HAVING COUNT(*) > 3\n) s\nJOIN (\n SELECT guest_id,\n SUM(amount_paid) AS total_amount_paid\n FROM hospitality_technology.reservations\n GROUP BY guest_id\n) p\n ON s.guest_id = p.guest_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )\n", "conversations": [{"role": "user", "content": "Find pairs of items from the same game, where one item is of type 'Weapon' and the other is of type 'Consumable'. List the game ID, the name of the weapon, and the name of the consumable."}, {"role": "assistant", "content": "SELECT i1.game_id, i1.item_name AS weapon_name, i2.item_name AS consumable_name FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.item_type = 'Weapon' AND i2.item_type = 'Consumable' AND i1.item_id != i2.item_id;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\n", "conversations": [{"role": "user", "content": "Show me the document name, upload timestamp, time entry date worked, and hours spent for all entries related to case 'CASE_XYZ'."}, {"role": "assistant", "content": "SELECT T1.document_name , T1.upload_timestamp , T2.date_worked , T2.hours_spent FROM documents AS T1 JOIN time_entries AS T2 ON T1.case_id = T2.case_id WHERE T1.case_id = 'CASE_XYZ'"}, {"role": "user", "content": "Only include time entries that are billable."}, {"role": "assistant", "content": "SELECT T1.document_name , T1.upload_timestamp , T2.date_worked , T2.hours_spent FROM documents AS T1 JOIN time_entries AS T2 ON T1.case_id = T2.case_id WHERE T1.case_id = 'CASE_XYZ' AND T2.is_billable = true"}, {"role": "user", "content": "Also, only show documents uploaded after 2024-01-01."}, {"role": "assistant", "content": "SELECT T1.document_name , T1.upload_timestamp , T2.date_worked , T2.hours_spent FROM documents AS T1 JOIN time_entries AS T2 ON T1.case_id = T2.case_id WHERE T1.case_id = 'CASE_XYZ' AND T2.is_billable = true AND T1.upload_timestamp >= '2024-01-01'"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "How many users does each user follow? Show the follower user ID and the count."}, {"role": "assistant", "content": "SELECT follower_user_id, count(*) FROM social_media.follows GROUP BY follower_user_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid, username text, email text, password_hash text, registration_date timestamp with time zone, last_login timestamp with time zone, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.games ( game_id uuid, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\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, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\n", "conversations": [{"role": "user", "content": "List all game titles and corresponding server names for servers that are located in the same region as 'us-central-1'."}, {"role": "assistant", "content": "SELECT g.title, s.server_name\nFROM gaming_technology.servers s\nJOIN gaming_technology.games g ON s.game_id = g.game_id\nWHERE s.region = 'us-central-1';"}, {"role": "user", "content": "Additionally, include the username of every player who has had a session on each of those servers."}, {"role": "assistant", "content": "SELECT g.title, s.server_name, p.username\nFROM gaming_technology.servers s\nJOIN gaming_technology.games g ON s.game_id = g.game_id\nJOIN gaming_technology.game_sessions gs ON gs.server_id = s.server_id\nJOIN gaming_technology.players p ON gs.player_id = p.player_id\nWHERE s.region = 'us-central-1';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "List the usernames and registration dates for all players from Germany ('DE') who are currently 'online'."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE country_code = 'DE' AND status = 'online';"}, {"role": "user", "content": "Now, for players in Germany ('DE'), show me the count of players for each different status recorded in the table."}, {"role": "assistant", "content": "SELECT status, COUNT(player_id) FROM gaming_technology.players WHERE country_code = 'DE' GROUP BY status;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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": "Show me the full names and contact emails of citizens who have received notifications via 'SMS'."}, {"role": "assistant", "content": "SELECT DISTINCT c.first_name, c.last_name, c.contact_email\nFROM government_services.citizens c\nJOIN government_services.notifications n ON c.citizen_id = n.citizen_id\nWHERE n.channel = 'SMS';"}, {"role": "user", "content": "I want to only see those citizens whose accounts are not verified."}, {"role": "assistant", "content": "SELECT DISTINCT c.first_name, c.last_name, c.contact_email\nFROM government_services.citizens c\nJOIN government_services.notifications n ON c.citizen_id = n.citizen_id\nWHERE n.channel = 'SMS' AND c.is_verified = false;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text PRIMARY KEY, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "Find the total payment amount and payment count made by citizen with national ID number 'A123456789'."}, {"role": "assistant", "content": "SELECT SUM(p.amount) AS total_amount, COUNT(p.payment_id) AS payment_count\nFROM government_services.citizens c\nJOIN government_services.payments p ON c.citizen_id = p.citizen_id\nWHERE c.national_id_number = 'A123456789';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.insurance_products ( product_id text, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List the product_id, product_name, and base_premium for all products that are currently inactive."}, {"role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE is_active = false;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claims ( claim_id text, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "I want a list of all claims where at least one document is larger than 2 megabytes. Include the claim ID, incident date, and the file name of such documents."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152;"}, {"role": "user", "content": "Actually, please also show the document type and only include documents uploaded after June 1, 2024."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01';"}, {"role": "user", "content": "Add the file size in kilobytes and order the results by file size descending."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type, (d.file_size_bytes/1024) AS file_size_kb\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01'\nORDER BY d.file_size_bytes DESC;"}, {"role": "user", "content": "Sorry, I'm getting some records where file_size_bytes is NULL. Please exclude those from the results."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type, (d.file_size_bytes/1024) AS file_size_kb\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01'\n AND d.file_size_bytes IS NOT NULL\nORDER BY d.file_size_bytes DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id.text, customer_id.text, product_id.text, agent_id.text, policy_number.text, start_date.date, end_date.date, premium_amount.numeric, coverage_limit.numeric, deductible.numeric, status.text, issued_at.timestamp, cancellation_date.date, cancellation_reason.text )\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.premium_payments ( payment_id.text, policy_id.text, customer_id.text, payment_date.timestamp, amount_paid.numeric, payment_method.text, transaction_reference.text, due_date.date, payment_period_start.date, payment_period_end.date, status.text )\n", "conversations": [{"role": "user", "content": "Show me all active policies with coverage limits above $1,000,000, along with the customer names and agent names, sorted by coverage limit in descending order."}, {"role": "assistant", "content": "SELECT p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.premium_amount, p.start_date, p.end_date FROM insurance.policies p WHERE p.status = 'active' AND p.coverage_limit > 1000000 ORDER BY p.coverage_limit DESC;"}, {"role": "user", "content": "Actually, I need to see the customer's first and last name from the customers table and the agent's full name from the agents table as well."}, {"role": "assistant", "content": "SELECT p.policy_id, p.coverage_limit, p.premium_amount, c.first_name AS customer_first_name, c.last_name AS customer_last_name, a.first_name AS agent_first_name, a.last_name AS agent_last_name FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.agents a ON p.agent_id = a.agent_id WHERE p.status = 'active' AND p.coverage_limit > 1000000 ORDER BY p.coverage_limit DESC;"}, {"role": "user", "content": "Now I also want to see the total number of claims each of these high-coverage policies has had."}, {"role": "assistant", "content": "SELECT p.policy_id, p.coverage_limit, p.premium_amount, c.first_name AS customer_first_name, c.last_name AS customer_last_name, a.first_name AS agent_first_name, a.last_name AS agent_last_name, COUNT(cl.claim_id) AS total_claims FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.agents a ON p.agent_id = a.agent_id LEFT JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'active' AND p.coverage_limit > 1000000 GROUP BY p.policy_id, p.coverage_limit, p.premium_amount, c.first_name, c.last_name, a.first_name, a.last_name ORDER BY p.coverage_limit DESC;"}, {"role": "user", "content": "Finally, filter these results to only show policies that have at least one claim and include the average settlement amount for those claims."}, {"role": "assistant", "content": "SELECT p.policy_id, p.coverage_limit, p.premium_amount, c.first_name AS customer_first_name, c.last_name AS customer_last_name, a.first_name AS agent_first_name, a.last_name AS agent_last_name, COUNT(cl.claim_id) AS total_claims, AVG(cl.settlement_amount) AS avg_settlement FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.agents a ON p.agent_id = a.agent_id JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'active' AND p.coverage_limit > 1000000 GROUP BY p.policy_id, p.coverage_limit, p.premium_amount, c.first_name, c.last_name, a.first_name, a.last_name HAVING COUNT(cl.claim_id) > 0 ORDER BY p.coverage_limit DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "Show the top 5 largest documents by file size, including document_id, claim_id, file_name, and file_size_bytes."}, {"role": "assistant", "content": "SELECT document_id,\n claim_id,\n file_name,\n file_size_bytes\nFROM insurance.claim_documents\nORDER BY file_size_bytes DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n", "conversations": [{"role": "user", "content": "Show the policy number, start date, and the first and last name of the agent for all policies that started in 2024."}, {"role": "assistant", "content": "SELECT p.policy_number, p.start_date, a.first_name AS agent_first_name, a.last_name AS agent_last_name\nFROM insurance.policies p\nJOIN insurance.agents a ON p.agent_id = a.agent_id\nWHERE p.start_date >= '2024-01-01' AND p.start_date < '2025-01-01';"}, {"role": "user", "content": "Also include the status of each policy and only show those where the policy's premium_amount is over 3000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.start_date, a.first_name AS agent_first_name, a.last_name AS agent_last_name, p.status, p.premium_amount\nFROM insurance.policies p\nJOIN insurance.agents a ON p.agent_id = a.agent_id\nWHERE p.start_date >= '2024-01-01' AND p.start_date < '2025-01-01' AND p.premium_amount > 3000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.premium_payments ( payment_id text, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the customer ID, payment ID, payment amount, and payment date for all premium payments with an amount paid over 2000."}, {"role": "assistant", "content": "SELECT customer_id, payment_id, amount_paid, payment_date\nFROM insurance.premium_payments\nWHERE amount_paid > 2000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve the number of open claims each customer has filed. Return customer_id, first_name, last_name, and open_claim_count."}, {"role": "assistant", "content": "SELECT cu.customer_id, cu.first_name, cu.last_name, COUNT(cl.claim_id) AS open_claim_count\nFROM insurance.customers cu\nLEFT JOIN insurance.claims cl ON cu.customer_id = cl.customer_id AND cl.status = 'Open'\nGROUP BY cu.customer_id, cu.first_name, cu.last_name;"}, {"role": "user", "content": "Now include only customers who have at least 3 open claims and order the results by open_claim_count descending."}, {"role": "assistant", "content": "SELECT cu.customer_id, cu.first_name, cu.last_name, COUNT(cl.claim_id) AS open_claim_count\nFROM insurance.customers cu\nJOIN insurance.claims cl ON cu.customer_id = cl.customer_id\nWHERE cl.status = 'Open'\nGROUP BY cu.customer_id, cu.first_name, cu.last_name\nHAVING COUNT(cl.claim_id) >= 3\nORDER BY open_claim_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\nCREATE TABLE insurance.premium_payments ( payment_id text, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n", "conversations": [{"role": "user", "content": "Show me all policies that have at least two premium payments associated with them, along with the total amount paid for each policy."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, COUNT(pp.payment_id) AS payment_count, SUM(pp.amount_paid) AS total_amount_paid\nFROM insurance.policies p\nJOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id\nGROUP BY p.policy_id, p.policy_number\nHAVING COUNT(pp.payment_id) >= 2;"}, {"role": "user", "content": "Actually, also include the start_date and status of each policy in the result."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, p.start_date, p.status, COUNT(pp.payment_id) AS payment_count, SUM(pp.amount_paid) AS total_amount_paid\nFROM insurance.policies p\nJOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id\nGROUP BY p.policy_id, p.policy_number, p.start_date, p.status\nHAVING COUNT(pp.payment_id) >= 2;"}, {"role": "user", "content": "Now restrict the result to only policies with status 'active'."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, p.start_date, p.status, COUNT(pp.payment_id) AS payment_count, SUM(pp.amount_paid) AS total_amount_paid\nFROM insurance.policies p\nJOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id\nWHERE p.status = 'active'\nGROUP BY p.policy_id, p.policy_number, p.start_date, p.status\nHAVING COUNT(pp.payment_id) >= 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\n", "conversations": [{"role": "user", "content": "List all agents and their managers' full names."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a LEFT JOIN insurance.agents m ON a.manager_id = m.agent_id;"}, {"role": "user", "content": "Filter the results to only include agents with a commission rate greater than 0.05."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a LEFT JOIN insurance.agents m ON a.manager_id = m.agent_id WHERE a.commission_rate > 0.05;"}, {"role": "user", "content": "From those results, also only show agents whose manager is licensed in 'CA'."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a JOIN insurance.agents m ON a.manager_id = m.agent_id WHERE a.commission_rate > 0.05 AND m.license_state = 'CA';"}, {"role": "user", "content": "Please refine the output to only include the agent's first name, last name, and the manager's full name, sorted by manager's last name descending, and limit to the top 5."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a JOIN insurance.agents m ON a.manager_id = m.agent_id WHERE a.commission_rate > 0.05 AND m.license_state = 'CA' ORDER BY m.last_name DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all insurance products of type 'Travel', including their product_id, product_name, and base_premium."}, {"role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE product_type = 'Travel';"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.prescriptions ( prescription_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed int, prescription_date timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of prescriptions issued to the same patient but for different medications, issued on the same date. Show the patient ID, the prescription IDs of the two prescriptions, and their medication IDs and prescription dates."}, {"role": "assistant", "content": "SELECT p1.patient_id, p1.prescription_id AS prescription1_id, p1.medication_id AS medication1_id, p2.prescription_id AS prescription2_id, p2.medication_id AS medication2_id, p1.prescription_date FROM healthcare.prescriptions p1 JOIN healthcare.prescriptions p2 ON p1.patient_id = p2.patient_id AND p1.prescription_date = p2.prescription_date AND p1.medication_id <> p2.medication_id AND p1.prescription_id < p2.prescription_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\n", "conversations": [{"role": "user", "content": "How many distinct posts does each hashtag appear in?"}, {"role": "assistant", "content": "SELECT hashtag_id, COUNT(DISTINCT post_id) AS post_count FROM social_media.post_hashtags GROUP BY hashtag_id;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.stations ( station_id 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\n", "conversations": [{"role": "user", "content": "Can you list all item names along with their type, rarity, and cost amount for every item in the database?"}, {"role": "assistant", "content": "SELECT item_name, item_type, rarity, cost_amount FROM gaming_technology.in_game_items;"}, {"role": "user", "content": "Can you show only items where the cost amount is less than 100?"}, {"role": "assistant", "content": "SELECT item_name, item_type, rarity, cost_amount FROM gaming_technology.in_game_items WHERE cost_amount < 100;"}, {"role": "user", "content": "I only want to see items that are of rarity 'Epic'."}, {"role": "assistant", "content": "SELECT item_name, item_type, rarity, cost_amount FROM gaming_technology.in_game_items WHERE cost_amount < 100 AND rarity = 'Epic';"}, {"role": "user", "content": "Could you also show the game_id for these items?"}, {"role": "assistant", "content": "SELECT game_id, item_name, item_type, rarity, cost_amount FROM gaming_technology.in_game_items WHERE cost_amount < 100 AND rarity = 'Epic';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the usernames and email addresses of all users who are participants in conversations where user 'U333' has sent at least one message."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.email\nFROM social_media.conversation_participants cp\nJOIN social_media.messages m ON cp.conversation_id = m.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE m.sender_user_id = 'U333';"}, {"role": "user", "content": "Exclude user 'U333' from the results."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.email\nFROM social_media.conversation_participants cp\nJOIN social_media.messages m ON cp.conversation_id = m.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE m.sender_user_id = 'U333' AND u.user_id <> 'U333';"}, {"role": "user", "content": "Now only include participants who joined the conversation after March 1, 2024."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.email\nFROM social_media.conversation_participants cp\nJOIN social_media.messages m ON cp.conversation_id = m.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE m.sender_user_id = 'U333' AND u.user_id <> 'U333'\n AND cp.joined_at > '2024-03-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\n", "conversations": [{"role": "user", "content": "List all guests currently checked in, showing their full name, room number, property name, and check-in date."}, {"role": "assistant", "content": "SELECT g.first_name || ' ' || g.last_name AS guest_name,\n r.room_number,\n p.property_name,\n res.check_in_date\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.guests g ON res.guest_id = g.guest_id\nJOIN hospitality_technology.rooms r ON res.room_id = r.room_id\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'CheckedIn';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\n", "conversations": [{"role": "user", "content": "Could you list all agencies along with the name of their parent agency?"}, {"role": "assistant", "content": "SELECT child.agency_name AS agency_name, parent.agency_name AS parent_agency_name FROM government_services.agencies AS child LEFT JOIN government_services.agencies AS parent ON child.parent_agency_id = parent.agency_id;"}, {"role": "user", "content": "Please only show the agencies that have a parent agency."}, {"role": "assistant", "content": "SELECT child.agency_name AS agency_name, parent.agency_name AS parent_agency_name FROM government_services.agencies AS child INNER JOIN government_services.agencies AS parent ON child.parent_agency_id = parent.agency_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE manufacturing.components (\n component_id character varying(64) NOT NULL, -- unique identifier for the component\n part_number character varying(100) NOT NULL UNIQUE, -- manufacturer-specific part number\n component_name character varying(255) NOT NULL, -- descriptive name (e.g., Landing Gear Strut, Wing Spar)\n description text, -- detailed description\n material_id character varying(64), -- FK linking to the material used\n supplier_id character varying(64), -- FK linking to the supplier\n weight_kg numeric(10,3), -- weight of the component in kg\n cost_usd numeric(12,2), -- cost of the component in USD\n criticality_level character varying(20), -- e.g., 'High', 'Medium', 'Low'\n PRIMARY KEY (component_id)\n)\nCREATE TABLE manufacturing.materials (\n material_id character varying(64) NOT NULL, -- unique identifier for the material\n material_name character varying(128) NOT NULL, -- common name (e.g., Titanium Alloy Grade 5, Carbon Fiber Prepreg)\n specification character varying(255), -- specification standard (e.g., AMS 4928)\n description text, -- detailed description of properties\n density_kg_m3 numeric(10, 4), -- density in kg per cubic meter\n tensile_strength_mpa integer, -- tensile strength in Megapascals\n PRIMARY KEY (material_id)\n)\nCREATE TABLE manufacturing.assembly_lines (\n line_id character varying(64) NOT NULL, -- unique identifier for the assembly line\n line_name character varying(128) NOT NULL, -- name of the line (e.g., Fuselage Assembly Line 1)\n location_building character varying(100), -- building where the line is located\n location_area character varying(100), -- specific area within the building\n aircraft_model_id character varying(64), -- FK to the primary aircraft model built on this line\n capacity_units_per_month integer, -- theoretical maximum output per month\n status character varying(50) NOT NULL, -- e.g., 'Active', 'Maintenance', 'Idle'\n PRIMARY KEY (line_id)\n)\nCREATE TABLE manufacturing.component_inventory (\n inventory_record_id character varying(64) NOT NULL, -- unique ID for this inventory record/batch\n component_id character varying(64) NOT NULL, -- FK to the component\n quantity integer NOT NULL, -- number of units of this component in stock for this batch\n location_warehouse character varying(100), -- warehouse identifier\n location_bin character varying(100), -- specific bin or shelf location\n received_date timestamp NOT NULL, -- when this batch was received\n expiry_date date, -- expiry date if applicable (e.g., for sealants, adhesives)\n batch_number character varying(100), -- supplier batch number\n last_updated timestamp NOT NULL, -- timestamp of the last update to this record\n PRIMARY KEY (inventory_record_id)\n)\n", "conversations": [{"role": "user", "content": "\u6211\u60f3\u67e5\u8be2\u67d0\u4e2a\u7279\u5b9a\u7ec4\u4ef6ID\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7ec4\u4ef6\u540d\u79f0\u3001\u6750\u6599\u540d\u79f0\u3001\u6750\u6599\u5bc6\u5ea6\u4ee5\u53ca\u4f9b\u5e94\u5546ID\uff0c\u540c\u65f6\u8fd8\u9700\u8981\u77e5\u9053\u8be5\u7ec4\u4ef6\u5728\u54ea\u4e2a\u88c5\u914d\u7ebf\u4e0a\u7684\u98de\u673a\u578b\u53f7ID\u3002"}, {"role": "assistant", "content": "SELECT c.component_id, c.component_name, m.material_name, m.density_kg_m3, c.supplier_id, al.aircraft_model_id\nFROM manufacturing.components c\nJOIN manufacturing.materials m ON c.material_id = m.material_id\nJOIN manufacturing.component_inventory ci ON c.component_id = ci.component_id\nJOIN manufacturing.assembly_lines al ON ci.location_warehouse = al.location_building\nWHERE c.component_id = 'specific_component_id';"}, {"role": "user", "content": "\u5982\u679c\u6211\u60f3\u53ea\u663e\u793a\u6750\u6599\u5bc6\u5ea6\u5927\u4e8e3000 kg/m3\u7684\u8bb0\u5f55\uff0c\u5e94\u8be5\u600e\u4e48\u4fee\u6539\uff1f"}, {"role": "assistant", "content": "SELECT c.component_id, c.component_name, m.material_name, m.density_kg_m3, c.supplier_id, al.aircraft_model_id\nFROM manufacturing.components c\nJOIN manufacturing.materials m ON c.material_id = m.material_id\nJOIN manufacturing.component_inventory ci ON c.component_id = ci.component_id\nJOIN manufacturing.assembly_lines al ON ci.location_warehouse = al.location_building\nWHERE c.component_id = 'specific_component_id' AND m.density_kg_m3 > 3000;"}, {"role": "user", "content": "\u80fd\u5426\u518d\u52a0\u4e0a\u4e00\u4e2a\u6761\u4ef6\uff0c\u53ea\u663e\u793a\u88c5\u914d\u7ebf\u72b6\u6001\u4e3a'Active'\u7684\u8bb0\u5f55\uff1f"}, {"role": "assistant", "content": "SELECT c.component_id, c.component_name, m.material_name, m.density_kg_m3, c.supplier_id, al.aircraft_model_id\nFROM manufacturing.components c\nJOIN manufacturing.materials m ON c.material_id = m.material_id\nJOIN manufacturing.component_inventory ci ON c.component_id = ci.component_id\nJOIN manufacturing.assembly_lines al ON ci.location_warehouse = al.location_building\nWHERE c.component_id = 'specific_component_id' AND m.density_kg_m3 > 3000 AND al.status = 'Active';"}, {"role": "user", "content": "\u6700\u540e\uff0c\u8bf7\u6309\u6750\u6599\u5bc6\u5ea6\u4ece\u9ad8\u5230\u4f4e\u5bf9\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f\u3002"}, {"role": "assistant", "content": "SELECT c.component_id, c.component_name, m.material_name, m.density_kg_m3, c.supplier_id, al.aircraft_model_id\nFROM manufacturing.components c\nJOIN manufacturing.materials m ON c.material_id = m.material_id\nJOIN manufacturing.component_inventory ci ON c.component_id = ci.component_id\nJOIN manufacturing.assembly_lines al ON ci.location_warehouse = al.location_building\nWHERE c.component_id = 'specific_component_id' AND m.density_kg_m3 > 3000 AND al.status = 'Active'\nORDER BY m.density_kg_m3 DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List the first and last names of passengers who share the same loyalty_program_id with at least one other passenger."}, {"role": "assistant", "content": "SELECT DISTINCT p1.first_name, p1.last_name\nFROM transportation.passengers p1\nJOIN transportation.passengers p2 ON p1.loyalty_program_id = p2.loyalty_program_id AND p1.passenger_id <> p2.passenger_id\nWHERE p1.loyalty_program_id IS NOT NULL;"}, {"role": "user", "content": "Now refine this list to only include passengers who joined after January 1, 2023."}, {"role": "assistant", "content": "SELECT DISTINCT p1.first_name, p1.last_name\nFROM transportation.passengers p1\nJOIN transportation.passengers p2 ON p1.loyalty_program_id = p2.loyalty_program_id AND p1.passenger_id <> p2.passenger_id\nWHERE p1.loyalty_program_id IS NOT NULL\n AND p1.created_at >= '2023-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id.text, customer_id.text, product_id.text, agent_id.text, policy_number.text, start_date.date, end_date.date, premium_amount.numeric, coverage_limit.numeric, deductible.numeric, status.text, issued_at.timestamp, cancellation_date.date, cancellation_reason.text )\n", "conversations": [{"role": "user", "content": "For each policy, find its immediate predecessor policy for the same customer. Return customer_id, predecessor policy_number, current policy_number, predecessor end_date, and current start_date."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1;"}, {"role": "user", "content": "Only include those where the gap between predecessor end_date and current start_date is less than 7 days."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1\n AND (current_start - prev_end) < INTERVAL '7 days';"}, {"role": "user", "content": "Also filter to include only customers whose customer_id starts with 'CUST'."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1\n AND (current_start - prev_end) < INTERVAL '7 days'\n AND customer_id LIKE 'CUST%';"}, {"role": "user", "content": "Finally, order the results by customer_id and current_start_date descending, limit to 10 rows."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1\n AND (current_start - prev_end) < INTERVAL '7 days'\n AND customer_id LIKE 'CUST%'\nORDER BY customer_id, current_start DESC\nLIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n", "conversations": [{"role": "user", "content": "For the latest snapshot time, list the total `usd_value` held by CEXes for each distinct `token_symbol` across all chains. Order the results by total value descending."}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT max(snapshot_time) as max_time\n FROM cex_token_balance\n)\nSELECT token_symbol, sum(usd_value) as total_usd_value\nFROM cex_token_balance ctb\nJOIN latest_snapshot ls ON ctb.snapshot_time = ls.max_time\nGROUP BY token_symbol\nORDER BY total_usd_value DESC;"}, {"role": "user", "content": "Now, filter this list to only include tokens where the total `usd_value` across all CEX holdings is greater than $5,000,000."}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT max(snapshot_time) as max_time\n FROM cex_token_balance\n)\nSELECT token_symbol, sum(usd_value) as total_usd_value\nFROM cex_token_balance ctb\nJOIN latest_snapshot ls ON ctb.snapshot_time = ls.max_time\nGROUP BY token_symbol\nHAVING sum(usd_value) > 5000000.0\nORDER BY total_usd_value DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n", "conversations": [{"role": "user", "content": "For each narrative in token_basic_info, compute the total liquidity and count of tokens from token_dexpool_info. Show narrative, total_liquidity, and token_count."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nGROUP BY tbi.narrative;"}, {"role": "user", "content": "Include only tokens where volume_24h > 500000 and price_change_percentage_6h > 0."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nWHERE td.volume_24h > 500000\n AND td.price_change_percentage_6h > 0\nGROUP BY tbi.narrative;"}, {"role": "user", "content": "Now join narrative_info to also get trend_rank and narrative volume_24h."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n ni.trend_rank,\n ni.volume_24h AS narrative_volume,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nJOIN narrative_info ni\n ON tbi.narrative = ni.narrative\nWHERE td.volume_24h > 500000\n AND td.price_change_percentage_6h > 0\nGROUP BY tbi.narrative, ni.trend_rank, ni.volume_24h;"}, {"role": "user", "content": "Finally, only keep narratives where trend_rank <= 10 and order by total_liquidity descending."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n ni.trend_rank,\n ni.volume_24h AS narrative_volume,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nJOIN narrative_info ni\n ON tbi.narrative = ni.narrative\nWHERE td.volume_24h > 500000\n AND td.price_change_percentage_6h > 0\n AND ni.trend_rank <= 10\nGROUP BY tbi.narrative, ni.trend_rank, ni.volume_24h\nORDER BY total_liquidity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n", "conversations": [{"role": "user", "content": "What is the average USD value per address for each narrative across all chains?"}, {"role": "assistant", "content": "SELECT\n narrative,\n AVG(usd_value / NULLIF(address_amount, 0)) AS avg_usd_per_address\nFROM smart_money_token_inflow\nGROUP BY narrative;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\n", "conversations": [{"role": "user", "content": "Show the top 5 narratives ranked by trend_rank (lowest is better). Include the narrative, trend rank, and number of tokens."}, {"role": "assistant", "content": "SELECT narrative, trend_rank, token_num FROM narrative_info ORDER BY trend_rank ASC LIMIT 5;"}, {"role": "user", "content": "Can you also add their 24h and 7d price change percentages in the output?"}, {"role": "assistant", "content": "SELECT narrative, trend_rank, token_num, price_change_percentage_24h, price_change_percentage_7d FROM narrative_info ORDER BY trend_rank ASC LIMIT 5;"}, {"role": "user", "content": "Now, I want to see only those narratives where the total 24h trading volume is above $10 million."}, {"role": "assistant", "content": "SELECT narrative, trend_rank, token_num, price_change_percentage_24h, price_change_percentage_7d, volume_24h FROM narrative_info WHERE volume_24h > 10000000 ORDER BY trend_rank ASC LIMIT 5;"}, {"role": "user", "content": "Can you show trend_rank as the last column?"}, {"role": "assistant", "content": "SELECT narrative, token_num, price_change_percentage_24h, price_change_percentage_7d, volume_24h, trend_rank FROM narrative_info WHERE volume_24h > 10000000 ORDER BY trend_rank ASC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\n", "conversations": [{"role": "user", "content": "For each token, show its token_id, decimals, and the average total_supply of all tokens with the same decimals."}, {"role": "assistant", "content": "SELECT t.token_id,\n t.decimals,\n avg_data.avg_total_supply\nFROM web3.tokens t\nJOIN (\n SELECT decimals,\n AVG(total_supply) AS avg_total_supply\n FROM web3.tokens\n GROUP BY decimals\n) AS avg_data\n ON t.decimals = avg_data.decimals;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\n", "conversations": [{"role": "user", "content": "Show me all rooms with their type names and base rates for property 'P001'."}, {"role": "assistant", "content": "SELECT r.room_id, r.room_number, rt.type_name, rt.base_rate\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id\nWHERE r.property_id = 'P001';"}, {"role": "user", "content": "Actually, only include rooms on floor 2 and above, and sort by base_rate descending."}, {"role": "assistant", "content": "SELECT r.room_id, r.room_number, rt.type_name, rt.base_rate, r.floor\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id\nWHERE r.property_id = 'P001' AND r.floor >= 2\nORDER BY rt.base_rate DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\n", "conversations": [{"role": "user", "content": "Show all rooms that are on floor 3."}, {"role": "assistant", "content": "SELECT room_id, property_id, room_number FROM hospitality_technology.rooms WHERE floor = 3;"}, {"role": "user", "content": "For these rooms, include the property name and room number."}, {"role": "assistant", "content": "SELECT r.room_number, p.property_name FROM hospitality_technology.rooms AS r JOIN hospitality_technology.properties AS p ON r.property_id = p.property_id WHERE r.floor = 3;"}, {"role": "user", "content": "Also, include the type name and current status for each room."}, {"role": "assistant", "content": "SELECT r.room_number, p.property_name, rt.type_name, r.status FROM hospitality_technology.rooms AS r JOIN hospitality_technology.properties AS p ON r.property_id = p.property_id JOIN hospitality_technology.room_types AS rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id WHERE r.floor = 3;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\n", "conversations": [{"role": "user", "content": "List all available services in the 'Housekeeping' department that cost less than 20."}, {"role": "assistant", "content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20;"}, {"role": "user", "content": "Sort the results by service_name in ascending order."}, {"role": "assistant", "content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20\nORDER BY service_name ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "List all service orders for spa services in the last month, including the guest ID and total price."}, {"role": "assistant", "content": "SELECT order_id, guest_id, total_price FROM hospitality_technology.service_orders WHERE service_id LIKE 'SPA%' AND order_timestamp >= NOW() - INTERVAL '1 month';"}, {"role": "user", "content": "Now, include only orders with a total price over $100 and order them by total price in descending order."}, {"role": "assistant", "content": "SELECT order_id, guest_id, total_price FROM hospitality_technology.service_orders WHERE service_id LIKE 'SPA%' AND order_timestamp >= NOW() - INTERVAL '1 month' AND total_price > 100 ORDER BY total_price DESC;"}, {"role": "user", "content": "The query is missing the property ID. Can you include that as well?"}, {"role": "assistant", "content": "SELECT so.order_id, so.guest_id, so.total_price, r.property_id FROM hospitality_technology.service_orders so JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE so.service_id LIKE 'SPA%' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100 ORDER BY so.total_price DESC;"}, {"role": "user", "content": "Actually, I need to see the service description too, and order by guest ID."}, {"role": "assistant", "content": "SELECT so.order_id, so.guest_id, so.total_price, r.property_id, so.notes AS service_description FROM hospitality_technology.service_orders so JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE so.service_id LIKE 'SPA%' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100 ORDER BY so.guest_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\n", "conversations": [{"role": "user", "content": "List all food and beverage services (category = 'Food & Beverage') with their names, prices, and units, where the price is less than $20."}, {"role": "assistant", "content": "SELECT service_name, price, unit FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20;"}, {"role": "user", "content": "Now, filter these results to only include services that are priced per item (unit = 'Per Item')."}, {"role": "assistant", "content": "SELECT service_name, price, unit FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20 AND unit = 'Per Item';"}, {"role": "user", "content": "The query is missing the department information. Can you include that as well?"}, {"role": "assistant", "content": "SELECT service_name, price, unit, department FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20 AND unit = 'Per Item';"}, {"role": "user", "content": "Actually, I only need services from the 'F&B' department, and order them by price in ascending order."}, {"role": "assistant", "content": "SELECT service_name, price, unit, department FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20 AND unit = 'Per Item' AND department = 'F&B' ORDER BY price ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "List each payment's currency_code, total amount paid, and the number of service orders placed by the same guest for the same reservation."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.currency_code,\n p.amount AS payment_amount,\n COUNT(so.order_id) AS order_count\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.service_orders so\n ON p.reservation_id = so.reservation_id\n AND p.guest_id = so.guest_id\nGROUP BY p.payment_id, p.currency_code, p.amount;"}, {"role": "user", "content": "Actually, I want the earliest service order date for each reservation and include it in the results."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.currency_code,\n p.amount AS payment_amount,\n COUNT(so.order_id) AS order_count,\n MIN(so.order_timestamp) AS first_order_timestamp\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.service_orders so\n ON p.reservation_id = so.reservation_id\n AND p.guest_id = so.guest_id\nGROUP BY p.payment_id, p.currency_code, p.amount;"}, {"role": "user", "content": "Also, only include payments with status = 'Succeeded' and service orders with status = 'Delivered'."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.currency_code,\n p.amount AS payment_amount,\n COUNT(so.order_id) AS order_count,\n MIN(so.order_timestamp) AS first_order_timestamp\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.service_orders so\n ON p.reservation_id = so.reservation_id\n AND p.guest_id = so.guest_id\n AND so.status = 'Delivered'\nWHERE p.status = 'Succeeded'\nGROUP BY p.payment_id, p.currency_code, p.amount;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id.text, property_id.text, first_name.text, last_name.text, position.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, is_active.boolean, access_level.integer, manager_id.text, created_at.timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\nCREATE TABLE hospitality_technology.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )\n", "conversations": [{"role": "user", "content": "List all rooms that have a 'Jacuzzi' feature, including the room_number, property_id, type_name, and base_rate."}, {"role": "assistant", "content": "SELECT r.room_number,\n r.property_id,\n rt.type_name,\n rt.base_rate\nFROM hospitality_technology.rooms AS r\nJOIN hospitality_technology.room_types AS rt\n ON r.room_type_id = rt.room_type_id\n AND r.property_id = rt.property_id\nWHERE r.features ILIKE '%Jacuzzi%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "Show me all staff members along with their positions and the names of the properties they work at."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id;"}, {"role": "user", "content": "Only include staff who are not currently active."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.is_active = FALSE;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n", "conversations": [{"role": "user", "content": "Find guests who ordered the same service more than once on the same reservation and date. Return guest_id, reservation_id, service_id, and the date."}, {"role": "assistant", "content": "SELECT so1.guest_id,\n so1.reservation_id,\n so1.service_id,\n DATE(so1.order_timestamp) AS order_date\nFROM hospitality_technology.service_orders so1\nJOIN hospitality_technology.service_orders so2\n ON so1.guest_id = so2.guest_id\n AND so1.reservation_id = so2.reservation_id\n AND so1.service_id = so2.service_id\n AND DATE(so1.order_timestamp) = DATE(so2.order_timestamp)\n AND so1.order_id < so2.order_id\nGROUP BY so1.guest_id, so1.reservation_id, so1.service_id, DATE(so1.order_timestamp);"}, {"role": "user", "content": "Actually, consider only orders where status = 'Delivered'."}, {"role": "assistant", "content": "SELECT so1.guest_id,\n so1.reservation_id,\n so1.service_id,\n DATE(so1.order_timestamp) AS order_date\nFROM hospitality_technology.service_orders so1\nJOIN hospitality_technology.service_orders so2\n ON so1.guest_id = so2.guest_id\n AND so1.reservation_id = so2.reservation_id\n AND so1.service_id = so2.service_id\n AND DATE(so1.order_timestamp) = DATE(so2.order_timestamp)\n AND so1.order_id < so2.order_id\nWHERE so1.status = 'Delivered'\n AND so2.status = 'Delivered'\nGROUP BY so1.guest_id, so1.reservation_id, so1.service_id, DATE(so1.order_timestamp);"}, {"role": "user", "content": "Also, count how many times each service was reordered per date and sort by that count descending."}, {"role": "assistant", "content": "SELECT so1.guest_id,\n so1.reservation_id,\n so1.service_id,\n DATE(so1.order_timestamp) AS order_date,\n COUNT(*) AS reorder_count\nFROM hospitality_technology.service_orders so1\nJOIN hospitality_technology.service_orders so2\n ON so1.guest_id = so2.guest_id\n AND so1.reservation_id = so2.reservation_id\n AND so1.service_id = so2.service_id\n AND DATE(so1.order_timestamp) = DATE(so2.order_timestamp)\n AND so1.order_id < so2.order_id\nWHERE so1.status = 'Delivered'\n AND so2.status = 'Delivered'\nGROUP BY so1.guest_id, so1.reservation_id, so1.service_id, DATE(so1.order_timestamp)\nORDER BY reorder_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\nCREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, property_id text, reservation_id text, guest_id text, rating_overall int, rating_cleanliness int, rating_service int, rating_location int, rating_value int, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "Show all public reviews that have a comment."}, {"role": "assistant", "content": "SELECT review_id, property_id, guest_id, rating_overall, comment FROM reviews WHERE is_public = TRUE AND comment IS NOT NULL AND comment != '';"}, {"role": "user", "content": "From those, only show reviews with an overall rating of 5."}, {"role": "assistant", "content": "SELECT review_id, property_id, guest_id, rating_overall, comment FROM reviews WHERE is_public = TRUE AND comment IS NOT NULL AND comment != '' AND rating_overall = 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id.text, citizen_id.text, service_id.text, submitted_at.timestamp, status.text, last_updated_at.timestamp, assigned_employee_id.text, decision_date.date, notes.text, reference_number.text )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "List the appointment IDs and statuses for all appointments scheduled at locations in the city of 'San Francisco'."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.status\nFROM government_services.appointments a\nJOIN government_services.service_locations l ON a.location_id = l.location_id\nWHERE l.city = 'San Francisco';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "Show the application ID, payment amount, and payment method for all payments that have a status of 'Completed' and are related to services in the 'Licensing' category."}, {"role": "assistant", "content": "SELECT p.application_id, p.amount, p.payment_method\nFROM government_services.payments p\nJOIN government_services.services s ON p.service_id = s.service_id\nWHERE p.status = 'Completed' AND s.category = 'Licensing';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\nCREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "How many total documents are recorded in the system?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM government_services.documents;"}, {"role": "user", "content": "Show me the count of documents for each verification_status."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) FROM government_services.documents GROUP BY verification_status;"}, {"role": "user", "content": "Exclude any documents where the verification_status is 'Pending' or 'Rejected'."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) FROM government_services.documents WHERE verification_status NOT IN ('Pending', 'Rejected') GROUP BY verification_status;"}, {"role": "user", "content": "And order the results by the count in descending order."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) FROM government_services.documents WHERE verification_status NOT IN ('Pending', 'Rejected') GROUP BY verification_status ORDER BY COUNT(*) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\n", "conversations": [{"role": "user", "content": "List all agencies that do not have a website URL specified. Return their agency_id, agency_name, and main_phone_number."}, {"role": "assistant", "content": "SELECT agency_id, agency_name, main_phone_number FROM government_services.agencies WHERE website_url IS NULL OR website_url = '';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n application_id character varying(64), -- FK to applications table (optional)\n message_subject character varying(255),\n message_body text NOT NULL,\n channel character varying(30) NOT NULL, -- e.g., Email, SMS, Portal Message, Mail\n sent_at timestamp NOT NULL,\n status character varying(30) NOT NULL, -- e.g., Queued, Sent, Delivered, Failed, Read\n related_entity_type character varying(50), -- e.g., Application, Appointment, Document Request\n related_entity_id character varying(64), -- ID of the related entity\n PRIMARY KEY (notification_id)\n)\n", "conversations": [{"role": "user", "content": "List the full names and job titles of all employees who have not verified any documents."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, e.job_title FROM government_services.employees AS e LEFT JOIN government_services.documents AS d ON e.employee_id = d.verified_by_employee_id WHERE d.document_id IS NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\n", "conversations": [{"role": "user", "content": "Find all document types uploaded by citizens whose documents have an expiry date in 2024 and were uploaded at locations located in the state of 'Nevada'. List the document_id, document_type, and location_name."}, {"role": "assistant", "content": "SELECT d.document_id, d.document_type, sl.location_name\nFROM government_services.documents d\nJOIN government_services.service_locations sl\n ON d.application_id = sl.location_id\nWHERE d.expiry_date BETWEEN '2024-01-01' AND '2024-12-31'\n AND sl.state = 'Nevada';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\n", "conversations": [{"role": "user", "content": "List the first name, last name, and job title of each employee, along with the job title of their manager."}, {"role": "assistant", "content": "SELECT e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.job_title AS employee_job_title, m.job_title AS manager_job_title FROM government_services.employees AS e LEFT JOIN government_services.employees AS m ON e.manager_employee_id = m.employee_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\n", "conversations": [{"role": "user", "content": "Find pairs of active services within the same category provided by the same agency, where one service has an average processing time more than double the other's. Display the agency ID, category, the first service name and its processing time, and the second service name and its processing time."}, {"role": "assistant", "content": "SELECT s1.agency_id, s1.category, s1.service_name AS service1_name, s1.average_processing_time_days AS service1_processing_time_days, s2.service_name AS service2_name, s2.average_processing_time_days AS service2_processing_time_days FROM government_services.services AS s1 JOIN government_services.services AS s2 ON s1.agency_id = s2.agency_id AND s1.category = s2.category AND s1.service_id < s2.service_id WHERE s1.is_active = TRUE AND s2.is_active = TRUE AND s1.average_processing_time_days IS NOT NULL AND s2.average_processing_time_days IS NOT NULL AND (s1.average_processing_time_days > 2 * s2.average_processing_time_days OR s2.average_processing_time_days > 2 * s1.average_processing_time_days);"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\n", "conversations": [{"role": "user", "content": "List the service name, category, and standard fee for all services offered by agencies that have at least one accessible service location in the state of 'California'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name, T1.category, T1.standard_fee FROM government_services.services AS T1 JOIN government_services.service_locations AS T2 ON T1.agency_id = T2.agency_id WHERE T2.is_accessible = TRUE AND T2.state = 'California';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Show me all upcoming appointments in July 2024, the citizen's full name, the name of the service, and the agency responsible for the service."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, c.first_name || ' ' || c.last_name AS citizen_full_name, s.service_name, ag.agency_name\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.services s ON a.service_id = s.service_id\nJOIN government_services.agencies ag ON s.agency_id = ag.agency_id\nWHERE a.scheduled_start_time >= '2024-07-01' AND a.scheduled_start_time < '2024-08-01'\nORDER BY a.scheduled_start_time ASC;"}, {"role": "user", "content": "Could you also include the status of each appointment and only show those which are still 'Scheduled'?"}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, c.first_name || ' ' || c.last_name AS citizen_full_name, s.service_name, ag.agency_name, a.status\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.services s ON a.service_id = s.service_id\nJOIN government_services.agencies ag ON s.agency_id = ag.agency_id\nWHERE a.scheduled_start_time >= '2024-07-01' AND a.scheduled_start_time < '2024-08-01'\n AND a.status = 'Scheduled'\nORDER BY a.scheduled_start_time ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "List agency_id, agency_name, and main_phone_number for agencies that do not have a main phone number specified."}, {"role": "assistant", "content": "SELECT agency_id, agency_name, main_phone_number\nFROM government_services.agencies\nWHERE main_phone_number IS NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Give me a list of all passengers with an email address on file, showing their first name, last name, and the date their record was created."}, {"role": "assistant", "content": "SELECT first_name, last_name, created_at\nFROM transportation.passengers\nWHERE email IS NOT NULL;"}, {"role": "user", "content": "Narrow the results to only include passengers who joined in 2022."}, {"role": "assistant", "content": "SELECT first_name, last_name, created_at\nFROM transportation.passengers\nWHERE email IS NOT NULL AND EXTRACT(YEAR FROM created_at) = 2022;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "What are the average and maximum fare amounts for each booking status?"}, {"role": "assistant", "content": "SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare\nFROM transportation.bookings\nGROUP BY status;"}, {"role": "user", "content": "Only include statuses where the average fare is greater than 50."}, {"role": "assistant", "content": "SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare\nFROM transportation.bookings\nGROUP BY status\nHAVING AVG(fare) > 50;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Can you show the fuel_log_id, vehicle make, and quantity for all fuel logs where the quantity is greater than 100?"}, {"role": "assistant", "content": "SELECT f.fuel_log_id, v.make, f.quantity\nFROM transportation.fuel_logs f\nJOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id\nWHERE f.quantity > 100;"}, {"role": "user", "content": "Also display the fuel type and order the results by quantity in descending order."}, {"role": "assistant", "content": "SELECT f.fuel_log_id, v.make, f.quantity, f.fuel_type\nFROM transportation.fuel_logs f\nJOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id\nWHERE f.quantity > 100\nORDER BY f.quantity DESC;"}, {"role": "user", "content": "Only include records from fuel logs that happened in 2023."}, {"role": "assistant", "content": "SELECT f.fuel_log_id, v.make, f.quantity, f.fuel_type\nFROM transportation.fuel_logs f\nJOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id\nWHERE f.quantity > 100\n AND EXTRACT(YEAR FROM f.log_timestamp) = 2023\nORDER BY f.quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the log timestamp, fuel type, quantity, and the name of the location for all fuel logs recorded at locations with type 'Warehouse'."}, {"role": "assistant", "content": "SELECT f.log_timestamp, f.fuel_type, f.quantity, l.name FROM transportation.fuel_logs f JOIN transportation.locations l ON f.location_id = l.location_id WHERE l.type = 'Warehouse';"}, {"role": "user", "content": "Filter these fuel logs to only include entries from the year 2024 and also include the total cost for each entry."}, {"role": "assistant", "content": "SELECT f.log_timestamp, f.fuel_type, f.quantity, f.total_cost, l.name FROM transportation.fuel_logs f JOIN transportation.locations l ON f.location_id = l.location_id WHERE l.type = 'Warehouse' AND EXTRACT(YEAR FROM f.log_timestamp) = 2024;"}, {"role": "user", "content": "For these 'Warehouse' fuel logs from 2024, calculate the average quantity and average cost_per_unit for each fuel type."}, {"role": "assistant", "content": "SELECT f.fuel_type, AVG(f.quantity) AS average_quantity, AVG(f.cost_per_unit) AS average_cost_per_unit FROM transportation.fuel_logs f JOIN transportation.locations l ON f.location_id = l.location_id WHERE l.type = 'Warehouse' AND EXTRACT(YEAR FROM f.log_timestamp) = 2024 GROUP BY f.fuel_type;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\n", "conversations": [{"role": "user", "content": "For each vehicle, find the vehicle acquired immediately before it in the same depot. Show current vehicle_id, acquisition_date, previous_vehicle_id, and previous_acquisition_date."}, {"role": "assistant", "content": "SELECT v.vehicle_id,\n v.acquisition_date,\n prev.vehicle_id AS previous_vehicle_id,\n prev.acquisition_date AS previous_acquisition_date\nFROM transportation.vehicles v\nLEFT JOIN transportation.vehicles prev\n ON v.depot_id = prev.depot_id\n AND prev.acquisition_date = (\n SELECT MAX(acquisition_date)\n FROM transportation.vehicles\n WHERE depot_id = v.depot_id\n AND acquisition_date < v.acquisition_date\n );"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n", "conversations": [{"role": "user", "content": "Show the booking ID and seat number for all bookings that have a fare equal to 50."}, {"role": "assistant", "content": "SELECT booking_id, seat_number\nFROM transportation.bookings\nWHERE fare = 50;"}, {"role": "user", "content": "Also include the booking status and order the results by booking time ascending."}, {"role": "assistant", "content": "SELECT booking_id, seat_number, status\nFROM transportation.bookings\nWHERE fare = 50\nORDER BY booking_time ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "Retrieve the daily total fare collected for bookings with status 'Completed' in March 2024. Display the booking_date and total_fare."}, {"role": "assistant", "content": "SELECT\n DATE(booking_time) AS booking_date,\n SUM(fare) AS total_fare\nFROM transportation.bookings\nWHERE status = 'Completed'\n AND booking_time >= '2024-03-01'\n AND booking_time < '2024-04-01'\nGROUP BY DATE(booking_time);"}, {"role": "user", "content": "Now include only days where the total_fare exceeds 1000."}, {"role": "assistant", "content": "SELECT\n DATE(booking_time) AS booking_date,\n SUM(fare) AS total_fare\nFROM transportation.bookings\nWHERE status = 'Completed'\n AND booking_time >= '2024-03-01'\n AND booking_time < '2024-04-01'\nGROUP BY DATE(booking_time)\nHAVING SUM(fare) > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\n", "conversations": [{"role": "user", "content": "Show me all maintenance logs for vehicles of make 'Toyota' performed after January 1, 2024. Include the log ID, vehicle ID, service date, and service type."}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, ml.service_type\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nWHERE v.make = 'Toyota' AND ml.service_date > '2024-01-01';"}, {"role": "user", "content": "Can you add the maintenance cost and mechanic name to each entry and sort the results by service date descending?"}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, ml.service_type, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nWHERE v.make = 'Toyota' AND ml.service_date > '2024-01-01'\nORDER BY ml.service_date DESC;"}, {"role": "user", "content": "Actually, only show logs where the maintenance cost is greater than 1000."}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, ml.service_type, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nWHERE v.make = 'Toyota' AND ml.service_date > '2024-01-01' AND ml.cost > 1000\nORDER BY ml.service_date DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\n", "conversations": [{"role": "user", "content": "Could you provide the number of vehicles for each fuel_type?"}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY fuel_type;"}, {"role": "user", "content": "Filter out fuel types having fewer than 10 vehicles."}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Now order the result by vehicle_count descending and limit to the top 5 entries."}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10\nORDER BY vehicle_count DESC\nLIMIT 5;"}, {"role": "user", "content": "Also add the average capacity for each fuel_type."}, {"role": "assistant", "content": "SELECT fuel_type,\n COUNT(*) AS vehicle_count,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10\nORDER BY vehicle_count DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n", "conversations": [{"role": "user", "content": "List the number of bookings made by each passenger, including passenger_id, first_name, last_name, and booking_count."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name;"}, {"role": "user", "content": "Actually, only include passengers who have made at least 2 bookings."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name\nHAVING COUNT(b.booking_id) >= 2;"}, {"role": "user", "content": "Also include the average fare per passenger."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count,\n AVG(b.fare) AS average_fare\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name\nHAVING COUNT(b.booking_id) >= 2;"}, {"role": "user", "content": "Sort the results by average_fare descending and limit to the top 5."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count,\n AVG(b.fare) AS average_fare\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name\nHAVING COUNT(b.booking_id) >= 2\nORDER BY average_fare DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\n", "conversations": [{"role": "user", "content": "Find pairs of distinct routes that share the same destination location but start from different origins. Include the route ID and route number for both routes and the shared destination location ID."}, {"role": "assistant", "content": "SELECT\n r1.route_id AS route1_id,\n r1.route_number AS route1_number,\n r2.route_id AS route2_id,\n r2.route_number AS route2_number,\n r1.destination_location_id AS shared_destination_location_id\nFROM transportation.routes AS r1\nJOIN transportation.routes AS r2\n ON r1.destination_location_id = r2.destination_location_id\n AND r1.route_id < r2.route_id\nWHERE\n r1.origin_location_id != r2.origin_location_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n", "conversations": [{"role": "user", "content": "List each booking with its previous booking time for the same passenger."}, {"role": "assistant", "content": "SELECT b.booking_id,\n b.passenger_id,\n b.booking_time,\n LAG(b.booking_time) OVER (PARTITION BY b.passenger_id ORDER BY b.booking_time) AS previous_booking_time\nFROM transportation.bookings b;"}, {"role": "user", "content": "I only want records where the gap between bookings is more than 7 days."}, {"role": "assistant", "content": "SELECT booking_id,\n passenger_id,\n booking_time,\n previous_booking_time\nFROM (\n SELECT booking_id,\n passenger_id,\n booking_time,\n LAG(booking_time) OVER (PARTITION BY passenger_id ORDER BY booking_time) AS previous_booking_time\n FROM transportation.bookings\n) t\nWHERE previous_booking_time IS NOT NULL\n AND booking_time - previous_booking_time > INTERVAL '7 days';"}, {"role": "user", "content": "Also include the total number of bookings for each passenger."}, {"role": "assistant", "content": "SELECT booking_id,\n passenger_id,\n booking_time,\n previous_booking_time,\n COUNT(*) OVER (PARTITION BY passenger_id) AS total_bookings\nFROM (\n SELECT booking_id,\n passenger_id,\n booking_time,\n LAG(booking_time) OVER (PARTITION BY passenger_id ORDER BY booking_time) AS previous_booking_time\n FROM transportation.bookings\n) t\nWHERE previous_booking_time IS NOT NULL\n AND booking_time - previous_booking_time > INTERVAL '7 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each user, what is the average time difference in days between their wallet creations? Return user_id and avg_diff_days."}, {"role": "assistant", "content": "WITH diffs AS (\n SELECT\n user_id,\n EXTRACT(EPOCH FROM (created_at - LAG(created_at) OVER (PARTITION BY user_id ORDER BY created_at))) / 86400 AS diff_days\n FROM web3.wallets\n)\nSELECT\n user_id,\n AVG(diff_days) AS avg_diff_days\nFROM diffs\nWHERE diff_days IS NOT NULL\nGROUP BY user_id;"}, {"role": "user", "content": "Actually, only include users who have created more than 2 wallets."}, {"role": "assistant", "content": "WITH diffs AS (\n SELECT\n user_id,\n EXTRACT(EPOCH FROM (created_at - LAG(created_at) OVER (PARTITION BY user_id ORDER BY created_at))) / 86400 AS diff_days\n FROM web3.wallets\n)\nSELECT\n user_id,\n AVG(diff_days) AS avg_diff_days\nFROM diffs\nWHERE diff_days IS NOT NULL\nGROUP BY user_id\nHAVING COUNT(diff_days) > 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text PRIMARY KEY, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.tokens ( token_id.text, contract_address.text, token_name.text, token_symbol.text, decimals.integer, total_supply.numeric )\nCREATE TABLE web3.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all failed transactions along with the from and to addresses, and the gas used."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used FROM web3.transactions WHERE status = 'failed';"}, {"role": "user", "content": "Actually, I also need to see the block number and timestamp for these failed transactions."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used, block_number, timestamp FROM web3.transactions WHERE status = 'failed';"}, {"role": "user", "content": "There's a typo in your SQL, it should be 'timestamp' not 'timestamp'. Also, sort the results by block number in descending order."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used, block_number, timestamp FROM web3.transactions WHERE status = 'failed' ORDER BY block_number DESC;"}, {"role": "user", "content": "Now filter to only show transactions with gas used greater than 100,000."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used, block_number, timestamp FROM web3.transactions WHERE status = 'failed' AND gas_used > 100000 ORDER BY block_number DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )\n", "conversations": [{"role": "user", "content": "For each transaction, show its transaction_id and the count of tokens transferred within that transaction."}, {"role": "assistant", "content": "SELECT transaction_id, COUNT(token_id) AS tokens_transferred FROM web3.token_transfers GROUP BY transaction_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of wallets that were created at the exact same timestamp but are owned by different users. List the IDs of both wallets and the shared creation timestamp."}, {"role": "assistant", "content": "SELECT\n w1.wallet_id AS wallet1_id,\n w2.wallet_id AS wallet2_id,\n w1.created_at\nFROM\n web3.wallets w1\nJOIN\n web3.wallets w2 ON w1.created_at = w2.created_at\nWHERE\n w1.wallet_id < w2.wallet_id\n AND w1.user_id != w2.user_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of users who registered on the same weekday but in different years. List the user ID and registration date for both users, and the weekday name."}, {"role": "assistant", "content": "SELECT u1.user_id, u1.created_at AS user1_created_at, u2.user_id, u2.created_at AS user2_created_at, TO_CHAR(u1.created_at, 'Day') AS registration_weekday FROM web3.users u1 JOIN web3.users u2 ON TO_CHAR(u1.created_at, 'Day') = TO_CHAR(u2.created_at, 'Day') AND EXTRACT(YEAR FROM u1.created_at) <> EXTRACT(YEAR FROM u2.created_at) AND u1.user_id < u2.user_id ORDER BY TO_CHAR(u1.created_at, 'D'), u1.created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\n", "conversations": [{"role": "user", "content": "For each user, find the previous user by registration time. List current user_id and username, previous user_id and username, and the time difference in minutes between their registrations."}, {"role": "assistant", "content": "SELECT u.user_id AS current_user_id,\n u.username AS current_username,\n p.user_id AS previous_user_id,\n p.username AS previous_username,\n EXTRACT(EPOCH FROM (u.created_at - p.created_at)) / 60 AS diff_minutes\nFROM web3.users u\nJOIN web3.users p\n ON p.created_at = (\n SELECT MAX(created_at)\n FROM web3.users\n WHERE created_at < u.created_at\n )\nORDER BY u.created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )\nCREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\n", "conversations": [{"role": "user", "content": "Calculate the total transfer volume and number of transfers for each Avalanche token tick over the past 7 days."}, {"role": "assistant", "content": "SELECT ta.tick,\n SUM(ta.amt) AS total_volume,\n COUNT(*) AS transfer_count\nFROM token_activities_avalanche ta\nWHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY ta.tick;"}, {"role": "user", "content": "Now include the creator from token_info and filter to tokens with total_volume > 500."}, {"role": "assistant", "content": "SELECT sub.tick,\n sub.total_volume,\n sub.transfer_count,\n ti.creator\nFROM (\n SELECT ta.tick,\n SUM(ta.amt) AS total_volume,\n COUNT(*) AS transfer_count\n FROM token_activities_avalanche ta\n WHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\n GROUP BY ta.tick\n) sub\nJOIN token_info ti ON sub.tick = ti.tick\nWHERE sub.total_volume > 500;"}, {"role": "user", "content": "Also add the current total_supply from token_balances_avalanche for each tick."}, {"role": "assistant", "content": "SELECT sub.tick,\n sub.total_volume,\n sub.transfer_count,\n ti.creator,\n tb.total_supply\nFROM (\n SELECT ta.tick,\n SUM(ta.amt) AS total_volume,\n COUNT(*) AS transfer_count\n FROM token_activities_avalanche ta\n WHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\n GROUP BY ta.tick\n) sub\nJOIN token_info ti ON sub.tick = ti.tick\nJOIN token_balances_avalanche tb ON sub.tick = tb.tick\nWHERE sub.total_volume > 500;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n", "conversations": [{"role": "user", "content": "For Avalanche tokens, show me the token `tick`, `creator`, and `max_supply` from the `token_info_avalanche` table."}, {"role": "assistant", "content": "SELECT tick, creator, max_supply FROM token_info_avalanche"}, {"role": "user", "content": "Now, for each of these ticks, calculate the total transfer volume (`amt`) from the `token_activities_avalanche` table over the last 30 days."}, {"role": "assistant", "content": "SELECT T1.tick, T2.creator, T2.max_supply, SUM(T1.amt) AS total_volume FROM token_activities_avalanche AS T1 JOIN token_info_avalanche AS T2 ON T1.tick = T2.tick WHERE T1.block_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30' DAY GROUP BY T1.tick, T2.creator, T2.max_supply"}, {"role": "user", "content": "Filter the results to only include ticks where the `total_volume` is greater than 10000."}, {"role": "assistant", "content": "SELECT T1.tick, T2.creator, T2.max_supply, SUM(T1.amt) AS total_volume FROM token_activities_avalanche AS T1 JOIN token_info_avalanche AS T2 ON T1.tick = T2.tick WHERE T1.block_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30' DAY GROUP BY T1.tick, T2.creator, T2.max_supply HAVING SUM(T1.amt) > 10000"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\n", "conversations": [{"role": "user", "content": "Compute the co-occurrence count for each hashtag pair across all posts."}, {"role": "assistant", "content": "SELECT ph1.hashtag_id AS tag_a, ph2.hashtag_id AS tag_b, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id;"}, {"role": "user", "content": "Only include pairs with co_occurrence_count >= 3."}, {"role": "assistant", "content": "SELECT ph1.hashtag_id AS tag_a, ph2.hashtag_id AS tag_b, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id\nHAVING COUNT(DISTINCT ph1.post_id) >= 3;"}, {"role": "user", "content": "Sort the results by co_occurrence_count descending and limit to the top 5 pairs."}, {"role": "assistant", "content": "SELECT ph1.hashtag_id AS tag_a, ph2.hashtag_id AS tag_b, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id\nHAVING COUNT(DISTINCT ph1.post_id) >= 3\nORDER BY co_occurrence_count DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\n", "conversations": [{"role": "user", "content": "List all group chats and the total count of messages sent in each one."}, {"role": "assistant", "content": "SELECT T1.group_name, count(T2.message_id) AS message_count FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE GROUP BY T1.group_name;"}, {"role": "user", "content": "Can you refine that to only show group chats that have more than 100 messages?"}, {"role": "assistant", "content": "SELECT T1.group_name, count(T2.message_id) AS message_count FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE GROUP BY T1.group_name HAVING count(T2.message_id) > 100;"}, {"role": "user", "content": "Great, now please also include the creation time of these group chats and order the results by the message count in descending order."}, {"role": "assistant", "content": "SELECT T1.group_name, T1.created_at, count(T2.message_id) AS message_count FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE GROUP BY T1.group_name, T1.created_at HAVING count(T2.message_id) > 100 ORDER BY message_count DESC;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\n", "conversations": [{"role": "user", "content": "For each user, show their username and how many unique conversations they have sent at least one message in where the conversation is a group chat."}, {"role": "assistant", "content": "SELECT u.username, COUNT(DISTINCT m.conversation_id) AS group_chats_messaged_in\nFROM social_media.users u\nJOIN social_media.messages m ON u.user_id = m.sender_user_id\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY u.username;"}, {"role": "user", "content": "Instead, show only users who have sent messages in more than one group chat, and include their email addresses."}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(DISTINCT m.conversation_id) AS group_chats_messaged_in\nFROM social_media.users u\nJOIN social_media.messages m ON u.user_id = m.sender_user_id\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY u.username, u.email\nHAVING COUNT(DISTINCT m.conversation_id) > 1;"}, {"role": "user", "content": "Also add the most recent message time sent by each user in these group chats."}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(DISTINCT m.conversation_id) AS group_chats_messaged_in, MAX(m.sent_at) AS last_message_time\nFROM social_media.users u\nJOIN social_media.messages m ON u.user_id = m.sender_user_id\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY u.username, u.email\nHAVING COUNT(DISTINCT m.conversation_id) > 1;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.transactions ( transaction_id text, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )\nCREATE TABLE financial_services.securities ( security_id.text, ticker_symbol.text, isin_code.text, cusip_code.text, security_name.text, security_type.text, exchange.text, currency.text, issuer_name.text, sector.text, last_updated.timestamp )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n", "conversations": [{"role": "user", "content": "List all employees hired in 2023 along with their job title and email."}, {"role": "assistant", "content": "SELECT employee_id, first_name, last_name, job_title, email\nFROM financial_services.employees\nWHERE EXTRACT(YEAR FROM hire_date) = 2023;"}, {"role": "user", "content": "Can you also include the full name of their direct manager for each employee?"}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name, e.last_name, e.job_title, e.email, CONCAT(m.first_name, ' ', m.last_name) AS manager_full_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE EXTRACT(YEAR FROM e.hire_date) = 2023;"}, {"role": "user", "content": "Now limit the output to only employees who are currently 'Active'."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name, e.last_name, e.job_title, e.email, CONCAT(m.first_name, ' ', m.last_name) AS manager_full_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE EXTRACT(YEAR FROM e.hire_date) = 2023 AND e.status = 'Active';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id.text, username.text, email.text, password_hash.text, full_name.text, profile_picture_url.text, bio.text, location.text, created_at.timestamp, updated_at.timestamp, is_verified.boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show the usernames of users who have followers and the total count of followers for each."}, {"role": "assistant", "content": "SELECT T1.username, COUNT(T2.follower_user_id) AS follower_count FROM social_media.users AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.following_user_id GROUP BY T1.user_id, T1.username;"}, {"role": "user", "content": "Modify to only include users whose accounts were created after '2023-01-01'."}, {"role": "assistant", "content": "SELECT T1.username, COUNT(T2.follower_user_id) AS follower_count FROM social_media.users AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.following_user_id WHERE T1.created_at > '2023-01-01' GROUP BY T1.user_id, T1.username;"}, {"role": "user", "content": "Order the results by follower count in descending order and limit to the top 10."}, {"role": "assistant", "content": "SELECT T1.username, COUNT(T2.follower_user_id) AS follower_count FROM social_media.users AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.following_user_id WHERE T1.created_at > '2023-01-01' GROUP BY T1.user_id, T1.username ORDER BY follower_count DESC LIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "Which fundraising projects in 2023 have an associated token, and what are their investment amounts, chain, and token narratives?"}, {"role": "assistant", "content": "SELECT p.project_name, p.investment_value, t.chain, t.narrative\nFROM project_fundraising_record p\nJOIN token_basic_info t \n ON LOWER(p.project_name) = LOWER(t.token_name)\nWHERE p.investment_date LIKE '2023%';"}, {"role": "user", "content": "Could you also include the token's symbol and current price in the results?"}, {"role": "assistant", "content": "SELECT p.project_name, p.investment_value, t.chain, t.narrative, t.token_symbol, t.price\nFROM project_fundraising_record p\nJOIN token_basic_info t \n ON LOWER(p.project_name) = LOWER(t.token_name)\nWHERE p.investment_date LIKE '2023%';"}, {"role": "user", "content": "Some matches may be missed. Can you use a more flexible join, such as where the token name contains the project name or vice versa (case-insensitive)?"}, {"role": "assistant", "content": "SELECT p.project_name, p.investment_value, t.chain, t.narrative, t.token_symbol, t.price\nFROM project_fundraising_record p\nJOIN token_basic_info t \n ON LOWER(p.project_name) = LOWER(t.token_name)\n OR LOWER(p.project_name) LIKE CONCAT('%', LOWER(t.token_name), '%')\n OR LOWER(t.token_name) LIKE CONCAT('%', LOWER(p.project_name), '%')\nWHERE p.investment_date LIKE '2023%';"}, {"role": "user", "content": "Add a filter to only include projects where the investment amount is greater than $2,000,000, and order by investment_value descending."}, {"role": "assistant", "content": "SELECT p.project_name, p.investment_value, t.chain, t.narrative, t.token_symbol, t.price\nFROM project_fundraising_record p\nJOIN token_basic_info t \n ON LOWER(p.project_name) = LOWER(t.token_name)\n OR LOWER(p.project_name) LIKE CONCAT('%', LOWER(t.token_name), '%')\n OR LOWER(t.token_name) LIKE CONCAT('%', LOWER(p.project_name), '%')\nWHERE p.investment_date LIKE '2023%'\n AND p.investment_value > 2000000\nORDER BY p.investment_value DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id.text, user_id.text, wallet_id.text, asset_id.text, order_type.text, quantity.numeric, price.numeric, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all orders, showing order ID, type, quantity, and price, that were placed using a wallet created after '2024-01-01'."}, {"role": "assistant", "content": "SELECT T1.order_id, T1.order_type, T1.quantity, T1.price FROM orders AS T1 JOIN wallets AS T2 ON T1.wallet_id = T2.wallet_id WHERE T2.created_at > '2024-01-01'"}, {"role": "user", "content": "From that list, only show orders with 'completed' status."}, {"role": "assistant", "content": "SELECT T1.order_id, T1.order_type, T1.quantity, T1.price FROM orders AS T1 JOIN wallets AS T2 ON T1.wallet_id = T2.wallet_id WHERE T2.created_at > '2024-01-01' AND T1.status = 'completed'"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\n", "conversations": [{"role": "user", "content": "Can you show me all pairs of trips that use the same vehicle but have different drivers? Please include both trip IDs, vehicle_id, and the driver_id for each trip."}, {"role": "assistant", "content": "SELECT t1.trip_id AS trip_id_1, t2.trip_id AS trip_id_2, t1.vehicle_id, t1.driver_id AS driver_id_1, t2.driver_id AS driver_id_2\nFROM transportation.trips t1\nJOIN transportation.trips t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\n AND t1.driver_id <> t2.driver_id;"}, {"role": "user", "content": "Actually, I also want to see only those pairs where both trips have a status of 'Completed'."}, {"role": "assistant", "content": "SELECT t1.trip_id AS trip_id_1, t2.trip_id AS trip_id_2, t1.vehicle_id, t1.driver_id AS driver_id_1, t2.driver_id AS driver_id_2\nFROM transportation.trips t1\nJOIN transportation.trips t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\n AND t1.driver_id <> t2.driver_id\nWHERE t1.status = 'Completed' AND t2.status = 'Completed';"}]} \ No newline at end of file +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "How many notifications have been sent by each sender? Show sender_user_id and notification count."}, {"role": "assistant", "content": "SELECT sender_user_id, COUNT(*) AS notification_count\nFROM social_media.notifications\nWHERE sender_user_id IS NOT NULL\nGROUP BY sender_user_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\n", "conversations": [{"role": "user", "content": "Count the number of comments that have been updated since they were first created."}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.comments WHERE updated_at > created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "I need the count of messages each user has sent per conversation, along with the conversation's group_name when it's a group chat."}, {"role": "assistant", "content": "SELECT m.sender_user_id,\n u.username,\n m.conversation_id,\n CASE WHEN c.is_group_chat THEN c.group_name ELSE 'Direct Chat' END AS chat_name,\n COUNT(*) AS total_messages\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nGROUP BY m.sender_user_id, u.username, m.conversation_id, c.is_group_chat, c.group_name;"}, {"role": "user", "content": "Only include conversations where the total messages exceed 5, and alias the count as message_count."}, {"role": "assistant", "content": "SELECT m.sender_user_id,\n u.username,\n m.conversation_id,\n CASE WHEN c.is_group_chat THEN c.group_name ELSE 'Direct Chat' END AS chat_name,\n COUNT(*) AS message_count\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nGROUP BY m.sender_user_id, u.username, m.conversation_id, c.is_group_chat, c.group_name\nHAVING COUNT(*) > 5;"}, {"role": "user", "content": "Exclude messages that have neither content nor media_url."}, {"role": "assistant", "content": "SELECT m.sender_user_id,\n u.username,\n m.conversation_id,\n CASE WHEN c.is_group_chat THEN c.group_name ELSE 'Direct Chat' END AS chat_name,\n COUNT(*) AS message_count\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nWHERE NOT ((m.content IS NULL OR m.content = '') AND m.media_url IS NULL)\nGROUP BY m.sender_user_id, u.username, m.conversation_id, c.is_group_chat, c.group_name\nHAVING COUNT(*) > 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "Show me all conversations that have more than 10 messages, along with the group name and the usernames of their participants."}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, u.username\nFROM social_media.conversations c\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nGROUP BY c.conversation_id, c.group_name, u.username\nHAVING COUNT(m.message_id) > 10;"}, {"role": "user", "content": "Instead, can you only show group chats where the group name contains 'Study' and list the time each participant joined?"}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, u.username, cp.joined_at\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true AND c.group_name ILIKE '%Study%';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the usernames and the group names for each user who has sent at least one message in a group chat."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.group_name\nFROM social_media.users u\nJOIN social_media.conversation_participants cp ON u.user_id = cp.user_id\nJOIN social_media.conversations c ON cp.conversation_id = c.conversation_id\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id AND u.user_id = m.sender_user_id\nWHERE c.is_group_chat = true;"}, {"role": "user", "content": "Can you include the total number of messages each user has sent in each group chat as well?"}, {"role": "assistant", "content": "SELECT u.username, c.group_name, COUNT(m.message_id) AS message_count\nFROM social_media.users u\nJOIN social_media.conversation_participants cp ON u.user_id = cp.user_id\nJOIN social_media.conversations c ON cp.conversation_id = c.conversation_id\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id AND u.user_id = m.sender_user_id\nWHERE c.is_group_chat = true\nGROUP BY u.username, c.group_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "What is the count of appointments for each lawyer? Display the lawyer ID and the total count."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments GROUP BY lawyer_id;"}, {"role": "user", "content": "Only show lawyers who have more than 5 appointments."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments GROUP BY lawyer_id HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Consider only appointments that were created in the year 2023."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments WHERE created_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59' GROUP BY lawyer_id HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Order the results by the appointment count in descending order."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments WHERE created_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59' GROUP BY lawyer_id HAVING COUNT(*) > 5 ORDER BY appointment_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\nCREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "What is the total sum of amounts paid for all invoices?"}, {"role": "assistant", "content": "SELECT SUM(amount_paid) FROM invoices;"}, {"role": "user", "content": "Group this total by the status of the invoice."}, {"role": "assistant", "content": "SELECT status, SUM(amount_paid) FROM invoices GROUP BY status;"}, {"role": "user", "content": "Only show statuses where the total amount paid is greater than 50000."}, {"role": "assistant", "content": "SELECT status, SUM(amount_paid) FROM invoices GROUP BY status HAVING SUM(amount_paid) > 50000;"}, {"role": "user", "content": "Order the results by the total paid amount in descending order."}, {"role": "assistant", "content": "SELECT status, SUM(amount_paid) FROM invoices GROUP BY status HAVING SUM(amount_paid) > 50000 ORDER BY SUM(amount_paid) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Show me the subject and start times of all appointments along with the corresponding lawyer IDs for each client."}, {"role": "assistant", "content": "SELECT client_id, lawyer_id, subject, start_time FROM legal_services.appointments;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n", "conversations": [{"role": "user", "content": "Get a list of appointment_id, start_time, and invoice_number for appointments that have a related invoice."}, {"role": "assistant", "content": "SELECT a.appointment_id,\n a.start_time,\n i.invoice_number\nFROM legal_services.appointments a\nJOIN legal_services.invoices i\n ON a.case_id = i.case_id;"}, {"role": "user", "content": "Also include only appointments that are completed and invoices that are fully paid (status 'Paid')."}, {"role": "assistant", "content": "SELECT a.appointment_id,\n a.start_time,\n i.invoice_number\nFROM legal_services.appointments a\nJOIN legal_services.invoices i\n ON a.case_id = i.case_id\nWHERE a.status = 'Completed'\n AND i.status = 'Paid';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all time entries from the last 90 days, including the entry description, hours spent, the name of the case, and the name of the client."}, {"role": "assistant", "content": "SELECT T1.description, T1.hours_spent, T2.case_name, T3.first_name, T3.last_name FROM legal_services.time_entries AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id JOIN clients AS T3 ON T2.client_id = T3.client_id WHERE T1.date_worked >= CURRENT_DATE - INTERVAL '90 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n", "conversations": [{"role": "user", "content": "I want to see a list of invoice_number and appointment_id for each invoice that has a scheduled appointment."}, {"role": "assistant", "content": "SELECT i.invoice_number,\n a.appointment_id\nFROM legal_services.invoices i\nJOIN legal_services.appointments a\n ON i.case_id = a.case_id\nWHERE a.status = 'Scheduled';"}, {"role": "user", "content": "Only include those invoices whose due_date is still in the future."}, {"role": "assistant", "content": "SELECT i.invoice_number,\n a.appointment_id\nFROM legal_services.invoices i\nJOIN legal_services.appointments a\n ON i.case_id = a.case_id\nWHERE a.status = 'Scheduled'\n AND i.due_date > CURRENT_DATE;"}, {"role": "user", "content": "Finally, sort the results by the invoice issue_date in descending order."}, {"role": "assistant", "content": "SELECT i.invoice_number,\n a.appointment_id\nFROM legal_services.invoices i\nJOIN legal_services.appointments a\n ON i.case_id = a.case_id\nWHERE a.status = 'Scheduled'\n AND i.due_date > CURRENT_DATE\nORDER BY i.issue_date DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n case_id character varying(64) NOT NULL, -- FK to cases table\n document_name character varying(255) NOT NULL, -- name of the document file\n document_type character varying(100), -- e.g., Pleading, Contract, Evidence, Correspondence\n storage_path text NOT NULL, -- path or reference to the document storage location\n uploaded_by_lawyer_id character varying(64), -- FK to lawyers table (who uploaded it)\n upload_timestamp timestamp NOT NULL, -- time the document was uploaded\n version integer DEFAULT 1, -- document version number\n description text, -- brief description or notes about the document\n PRIMARY KEY (document_id)\n)\n", "conversations": [{"role": "user", "content": "List the document name, type, version, and description for all documents."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents;"}, {"role": "user", "content": "Only include documents where the description is not null."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents WHERE description IS NOT NULL;"}, {"role": "user", "content": "Also, filter to only show documents with a version greater than 2."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents WHERE description IS NOT NULL AND version > 2;"}, {"role": "user", "content": "Order the results by upload timestamp descending."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents WHERE description IS NOT NULL AND version > 2 ORDER BY upload_timestamp DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.documents ( document_id text PRIMARY KEY, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version int, description text )\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n", "conversations": [{"role": "user", "content": "Show me a list of all appointments with the subject and full name of the assigned lawyer."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.subject, l.first_name || ' ' || l.last_name AS lawyer_full_name\nFROM legal_services.appointments a\nJOIN legal_services.lawyers l ON a.lawyer_id = l.lawyer_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\nCREATE TABLE insurance.policies ( policy_id.text, customer_id.text, product_id.text, agent_id.text, policy_number.text, start_date.date, end_date.date, premium_amount.numeric, coverage_limit.numeric, deductible.numeric, status.text, issued_at.timestamp, cancellation_date.date, cancellation_reason.text )\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.agents ( agent_id.text, first_name.text, last_name.text, agency_name.text, license_number.text, license_state.text, contact_email.text, contact_phone.text, hire_date.date, termination_date.date, status.text, commission_rate.numeric, manager_id.text )\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id.text, policy_id.text, customer_id.text, first_name.text, last_name.text, relationship.text, percentage_share.numeric, contact_info.text, added_at.timestamp )\n", "conversations": [{"role": "user", "content": "For every customer, show their first name, last name, and the policy number of any policies they own."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.policy_number FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id;"}, {"role": "user", "content": "Only include policies with status 'Active' or 'Pending'. Also add the policy start date to the results."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.policy_number, T2.start_date FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id WHERE T2.status IN ('Active', 'Pending');"}, {"role": "user", "content": "Further filter the customers to only those in California ('CA'). Order the results by the customer's last name and then first name."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.policy_number, T2.start_date FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id WHERE T2.status IN ('Active', 'Pending') AND T1.state = 'CA' ORDER BY T1.last_name, T1.first_name;"}, {"role": "user", "content": "Instead of listing each policy, tell me how many 'Active' or 'Pending' policies each of these California customers has. Show their full name and the count."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, COUNT(T2.policy_id) FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id WHERE T2.status IN ('Active', 'Pending') AND T1.state = 'CA' GROUP BY T1.customer_id, T1.first_name, T1.last_name ORDER BY T1.last_name, T1.first_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128), -- address of the receiver (can be null for contract deployment)\n value numeric(38,14) NOT NULL, -- value transferred\n gas_used integer NOT NULL, -- amount of gas used by the transaction\n gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction\n block_number integer NOT NULL, -- block number containing the transaction\n timestamp timestamp NOT NULL, -- time when the transaction was mined\n input_data text, -- input data of the transaction (can be null)\n status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)\n nonce integer NOT NULL, -- nonce of the sender at the time of the transaction\n PRIMARY KEY (transaction_id)\n)\n", "conversations": [{"role": "user", "content": "Find the top 5 transactions with the highest gas prices, including the from_address, to_address, and block_number, sorted by gas_price in descending order."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, block_number, gas_price FROM web3.transactions ORDER BY gas_price DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.tokens ( token_id text, contract_address text, token_name text, token_symbol text, decimals integer, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all contracts and the number of different tokens associated with each contract address. Show contract_id, contract address, and token_count."}, {"role": "assistant", "content": "SELECT c.contract_id, c.address, COUNT(DISTINCT t.token_id) AS token_count\nFROM web3.contracts c\nLEFT JOIN web3.tokens t ON c.address = t.contract_address\nGROUP BY c.contract_id, c.address;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\n", "conversations": [{"role": "user", "content": "Which agents, along with their managers' full names, are licensed in 'TX' and are currently active?"}, {"role": "assistant", "content": "SELECT a.agent_id, a.first_name AS agent_first_name, a.last_name AS agent_last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name\nFROM insurance.agents a\nLEFT JOIN insurance.agents m ON a.manager_id = m.agent_id\nWHERE a.license_state = 'TX' AND a.status = 'Active';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n", "conversations": [{"role": "user", "content": "Show me the total transfer volume and number of transfers for each token tick on Bitcoin in the past 7 days."}, {"role": "assistant", "content": "SELECT tick, SUM(amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities_bitcoin\nWHERE block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY tick;"}, {"role": "user", "content": "Can you also include the creator of each token by joining with token_info_bitcoin?"}, {"role": "assistant", "content": "SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities_bitcoin ta\nLEFT JOIN (\n SELECT tick, creator FROM token_info_bitcoin WHERE (tick, block_timestamp) IN (\n SELECT tick, MAX(block_timestamp) FROM token_info_bitcoin GROUP BY tick\n )\n) ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY ta.tick, ti.creator;"}, {"role": "user", "content": "Only include tokens where the total_volume is greater than 1000 and sort by total_volume descending, limit to top 5 tokens."}, {"role": "assistant", "content": "SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities_bitcoin ta\nLEFT JOIN (\n SELECT tick, creator FROM token_info_bitcoin WHERE (tick, block_timestamp) IN (\n SELECT tick, MAX(block_timestamp) FROM token_info_bitcoin GROUP BY tick\n )\n) ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY ta.tick, ti.creator\nHAVING SUM(ta.amt) > 1000\nORDER BY total_volume DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "Show the vehicle ID and the total number of fuel logs recorded for each vehicle."}, {"role": "assistant", "content": "SELECT vehicle_id , count(*) FROM transportation.fuel_logs GROUP BY vehicle_id"}, {"role": "user", "content": "Filter this list to only show vehicles with more than 5 fuel log entries."}, {"role": "assistant", "content": "SELECT vehicle_id , count(*) FROM transportation.fuel_logs GROUP BY vehicle_id HAVING count(*) > 5"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n", "conversations": [{"role": "user", "content": "List all partners who have provided a phone number, showing their full name and email."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL;"}, {"role": "user", "content": "Okay, now only include those partners hired between 2020-01-01 and 2022-12-31."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL AND hire_date BETWEEN '2020-01-01' AND '2022-12-31';"}, {"role": "user", "content": "Can you also add their specialization to the output?"}, {"role": "assistant", "content": "SELECT first_name, last_name, email, specialization FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL AND hire_date BETWEEN '2020-01-01' AND '2022-12-31';"}, {"role": "user", "content": "Finally, order the results by specialization in ascending order, then by last name."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, specialization FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL AND hire_date BETWEEN '2020-01-01' AND '2022-12-31' ORDER BY specialization ASC, last_name ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "Show me the email addresses and hire dates for all staff who have a manager."}, {"role": "assistant", "content": "SELECT work_email, hire_date\nFROM hospitality_technology.staff\nWHERE manager_id IS NOT NULL;"}, {"role": "user", "content": "Only include staff who were hired after January 1, 2023."}, {"role": "assistant", "content": "SELECT work_email, hire_date\nFROM hospitality_technology.staff\nWHERE manager_id IS NOT NULL AND hire_date > '2023-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Get the total number of appointments grouped by status."}, {"role": "assistant", "content": "SELECT status,\n COUNT(*) AS appointment_count\nFROM healthcare.appointments\nGROUP BY status;"}, {"role": "user", "content": "Now filter to include only statuses with more than 50 appointments."}, {"role": "assistant", "content": "SELECT status,\n COUNT(*) AS appointment_count\nFROM healthcare.appointments\nGROUP BY status\nHAVING COUNT(*) > 50;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\n", "conversations": [{"role": "user", "content": "List all group chats created in 2024, showing the group_name, conversation_id, and creation time."}, {"role": "assistant", "content": "SELECT conversation_id, group_name, created_at\nFROM social_media.conversations\nWHERE is_group_chat = true AND created_at >= '2024-01-01' AND created_at < '2025-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (doctor_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n", "conversations": [{"role": "user", "content": "Which patients have a primary insurance policy and are subscribed to a plan provided by 'Cigna'? List patient ID, full name, policy number, plan ID, and insurance provider."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, pi.policy_number, pi.plan_id, ip.insurance_provider\nFROM healthcare.patient_insurance pi\nJOIN healthcare.patients p ON pi.patient_id = p.patient_id\nJOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id\nWHERE pi.is_primary = true AND ip.insurance_provider = 'Cigna';"}, {"role": "user", "content": "Additionally, only show results where the policy has not expired yet."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, pi.policy_number, pi.plan_id, ip.insurance_provider\nFROM healthcare.patient_insurance pi\nJOIN healthcare.patients p ON pi.patient_id = p.patient_id\nJOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id\nWHERE pi.is_primary = true AND ip.insurance_provider = 'Cigna' AND (pi.expiration_date IS NULL OR pi.expiration_date >= CURRENT_DATE);"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers ( lawyer_id text, first_name text, last_name text, bar_number text, firm_id text, email text, phone text, specialization text, hire_date timestamp, is_partner boolean )\nCREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "I need a list showing the name of each law firm and the full name of every lawyer employed by that firm."}, {"role": "assistant", "content": "SELECT T1.firm_name, T2.first_name, T2.last_name FROM law_firms AS T1 JOIN lawyers AS T2 ON T1.firm_id = T2.firm_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "Show me all customers (customer_id, first_name, last_name, email) who were born after 1985 (date_of_birth > '1985-12-31') and have an email address ending with '@yahoo.com', along with their city and state information."}, {"role": "assistant", "content": "SELECT customer_id, first_name, last_name, email, city, state FROM financial_services.customers WHERE date_of_birth > '1985-12-31' AND email LIKE '%@yahoo.com';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )\nCREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) )\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.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.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id 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) )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "How many public posts has each verified user created since 2024-01-01? Please list their username and post_count."}, {"role": "assistant", "content": "SELECT u.username, COUNT(p.post_id) AS post_count FROM social_media.users u LEFT JOIN social_media.posts p ON u.user_id = p.user_id AND p.visibility = 'public' AND p.created_at >= '2024-01-01' WHERE u.is_verified = TRUE GROUP BY u.username;"}, {"role": "user", "content": "Add the average number of comments per post for each user alongside post_count."}, {"role": "assistant", "content": "SELECT u.username, COUNT(p.post_id) AS post_count, CASE WHEN COUNT(p.post_id) > 0 THEN COUNT(c.comment_id)::float / COUNT(DISTINCT p.post_id) ELSE 0 END AS avg_comments_per_post FROM social_media.users u LEFT JOIN social_media.posts p ON u.user_id = p.user_id AND p.visibility = 'public' AND p.created_at >= '2024-01-01' LEFT JOIN social_media.comments c ON c.post_id = p.post_id WHERE u.is_verified = TRUE GROUP BY u.username;"}]}