conversations
listlengths 2
8
| system
stringlengths 288
8.23k
|
|---|---|
[
{
"role": "user",
"content": "Show the full names and registration dates of citizens who have submitted applications with the status 'Processing'."
},
{
"role": "assistant",
"content": "SELECT DISTINCT c.first_name, c.last_name, c.registration_date\nFROM government_services.citizens c\nJOIN government_services.applications a ON c.citizen_id = a.citizen_id\nWHERE a.status = 'Processing';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.citizens (
citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen
national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
date_of_birth date NOT NULL,
gender character varying(20),
primary_address text NOT NULL, -- full primary residential address
contact_email character varying(128) UNIQUE,
contact_phone character varying(32),
registration_date timestamp NOT NULL, -- when the citizen profile was created
is_verified boolean DEFAULT false, -- whether identity has been officially verified
PRIMARY KEY (citizen_id)
)
CREATE TABLE government_services.applications (
application_id character varying(64) NOT NULL, -- unique identifier for the application
citizen_id character varying(64) NOT NULL, -- FK to citizens table
service_id character varying(64) NOT NULL, -- FK to services table
submitted_at timestamp NOT NULL, -- time the application was submitted
status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info
last_updated_at timestamp NOT NULL, -- time the status or details last changed
assigned_employee_id character varying(64), -- FK to employees table (optional)
decision_date date, -- date when a final decision was made
notes text, -- internal notes or citizen-provided comments
reference_number character varying(100) UNIQUE, -- publicly visible reference number
PRIMARY KEY (application_id)
)
|
[
{
"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 = '';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.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) )
|
[
{
"role": "user",
"content": "Can you list all SUI coins with 'active' status and their owner addresses and balances?"
},
{
"role": "assistant",
"content": "SELECT object_id, coin_type, owner, balance\nFROM sui_coins\nWHERE status = 'active';"
},
{
"role": "user",
"content": "Add the coin symbol and name from the sui_coins_metadata table."
},
{
"role": "assistant",
"content": "SELECT sc.object_id, sc.coin_type, sc.owner, sc.balance, scm.symbol, scm.name\nFROM sui_coins sc\nLEFT JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active';"
},
{
"role": "user",
"content": "Only include coins where the description mentions 'utility'."
},
{
"role": "assistant",
"content": "SELECT sc.object_id, sc.coin_type, sc.owner, sc.balance, scm.symbol, scm.name\nFROM sui_coins sc\nLEFT JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active' AND scm.description ILIKE '%utility%';"
},
{
"role": "user",
"content": "Limit the output to the top 10 coins sorted by balance descending."
},
{
"role": "assistant",
"content": "SELECT sc.object_id, sc.coin_type, sc.owner, sc.balance, scm.symbol, scm.name\nFROM sui_coins sc\nLEFT JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active' AND scm.description ILIKE '%utility%'\nORDER BY CAST(sc.balance AS BIGINT) DESC\nLIMIT 10;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )
CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )
CREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )
CREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )
CREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )
CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )
CREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )
CREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )
CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )
CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )
CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
CREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
|
[
{
"role": "user",
"content": "Show me the number of players registered in each country, along with the number of different games available for each country."
},
{
"role": "assistant",
"content": "SELECT p.country_code, COUNT(DISTINCT p.player_id) AS player_count, COUNT(DISTINCT g.game_id) AS game_count\nFROM gaming_technology.players p\nCROSS JOIN gaming_technology.games g\nGROUP BY p.country_code;"
},
{
"role": "user",
"content": "This doesn't make sense; the game count should be the number of games, not all possible combinations. Can you fix it to just show the count of players per country?"
},
{
"role": "assistant",
"content": "SELECT p.country_code, COUNT(*) AS player_count\nFROM gaming_technology.players p\nGROUP BY p.country_code;"
},
{
"role": "user",
"content": "Now add in the total number of servers located in each country, based on the players' country code matching the server's region."
},
{
"role": "assistant",
"content": "SELECT p.country_code, COUNT(*) AS player_count,\n (SELECT COUNT(*) FROM gaming_technology.servers s WHERE s.region = p.country_code) AS server_count\nFROM gaming_technology.players p\nGROUP BY p.country_code;"
},
{
"role": "user",
"content": "Show only countries where there are at least 5 servers."
},
{
"role": "assistant",
"content": "SELECT p.country_code, COUNT(*) AS player_count,\n (SELECT COUNT(*) FROM gaming_technology.servers s WHERE s.region = p.country_code) AS server_count\nFROM gaming_technology.players p\nGROUP BY p.country_code\nHAVING (SELECT COUNT(*) FROM gaming_technology.servers s WHERE s.region = p.country_code) >= 5;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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 )
CREATE TABLE gaming_technology.games (
game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game
title character varying(200) NOT NULL, -- official title of the game
developer_id uuid NOT NULL, -- FK linking to the developers table
publisher_id uuid, -- FK linking to a potential publishers table (optional)
genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)
release_date date, -- official release date
description text, -- short description or synopsis of the game
platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)
engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)
website character varying(255), -- official website URL
PRIMARY KEY (game_id)
-- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint
)
CREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )
CREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )
CREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )
|
[
{
"role": "user",
"content": "List all properties that have at least one room with 'Ocean View' in its features, showing the property name and the total count of such rooms."
},
{
"role": "assistant",
"content": "SELECT T1.property_name, COUNT(T2.room_id) FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.rooms AS T2 ON T1.property_id = T2.property_id WHERE T2.features LIKE '%Ocean View%' GROUP BY T1.property_id;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.properties (
property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)
property_name character varying(255) NOT NULL, -- name of the property
address_line1 character varying(255) NOT NULL, -- primary address line
address_line2 character varying(255), -- secondary address line
city character varying(100) NOT NULL, -- city
state_province character varying(100), -- state or province
postal_code character varying(20) NOT NULL, -- zip or postal code
country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)
phone_number character varying(30), -- main contact phone
email_address character varying(255), -- main contact email
property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel
star_rating numeric(2,1), -- star rating (e.g., 4.5)
timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)
manager_staff_id character varying(64), -- FK to staff table for the general manager
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time
updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time
PRIMARY KEY (property_id)
)
CREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )
CREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )
CREATE TABLE hospitality_technology.reservations ( reservation_id 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 )
CREATE TABLE hospitality_technology.services ( service_id.text, property_id.text, service_name.text, description.text, category.text, price.numeric, unit.text, is_available.boolean, department.text )
CREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )
|
[
{
"role": "user",
"content": "Show me the document name and the date worked for time entries logged by the same lawyer."
},
{
"role": "assistant",
"content": "SELECT T1.document_name , T2.date_worked FROM documents AS T1 JOIN time_entries AS T2 ON T1.uploaded_by_lawyer_id = T2.lawyer_id"
},
{
"role": "user",
"content": "Only show pairs where the time entry is billable."
},
{
"role": "assistant",
"content": "SELECT T1.document_name , T2.date_worked FROM documents AS T1 JOIN time_entries AS T2 ON T1.uploaded_by_lawyer_id = T2.lawyer_id WHERE T2.is_billable = true"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )
CREATE TABLE legal_services.time_entries (
entry_id character varying(64) NOT NULL, -- unique identifier for the time entry
case_id character varying(64) NOT NULL, -- FK to cases table
lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)
date_worked date NOT NULL, -- date the work was performed
hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)
billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry
description text NOT NULL, -- detailed description of the work performed
is_billable boolean DEFAULT true, -- whether this time entry is billable to the client
is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice
invoice_id character varying(64), -- FK to invoices table (once billed)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded
PRIMARY KEY (entry_id)
)
|
[
{
"role": "user",
"content": "Count the total number of premium payments made in the year 2024."
},
{
"role": "assistant",
"content": "SELECT COUNT(*) FROM premium_payments WHERE EXTRACT(YEAR FROM payment_date) = 2024"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE insurance.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 )
CREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )
CREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )
CREATE TABLE insurance.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 )
CREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )
|
[
{
"role": "user",
"content": "Can you help me fetch the inventory details for components associated with a specific aircraft build, including the batch number, quantity, and warehouse location?"
},
{
"role": "assistant",
"content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"
},
{
"role": "user",
"content": "Can you modify this to show only inventory batches received after a specific date, say June 1, 2023?"
},
{
"role": "assistant",
"content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01')\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"
},
{
"role": "user",
"content": "What if I also want to exclude batches with quantities less than 10?"
},
{
"role": "assistant",
"content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01') AND ib.quantity >= 10\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
Node Label ':AircraftModel'. Properties: { model_id: String (Constraint: UNIQUE), model_name: String, manufacturer: String, passenger_capacity: Integer, max_range_km: Integer, engine_type: String, wingspan_m: Float, status: String, first_flight_date: Date }. Index on model_id.
Node Label ':Material'. Properties: { material_id: String (Constraint: UNIQUE), material_name: String, specification: String, description: String, density_kg_m3: Float, tensile_strength_mpa: Integer }. Index on material_id.
Node Label ':AssemblyLine'. Properties: { line_id: String (Constraint: UNIQUE), line_name: String, location_building: String, location_area: String, capacity_units_per_month: Integer, status: String }. Relationship: (:AssemblyLine)-[:BUILDS_MODEL]->(:AircraftModel {model_id}). Index on line_id.
Node Label ':AssemblyStep'. Properties: { step_id: String (Constraint: UNIQUE), step_number: Integer, step_name: String, description: String, standard_duration_hours: Float, required_skill_level: String, workstation: String }. Relationship: (:AssemblyLine {line_id})-[:HAS_STEP {sequence: <step_number>}]->(:AssemblyStep). Index on step_id.
Node Label ':AircraftBuild'. Properties: { build_id: String (Constraint: UNIQUE), serial_number: String (Constraint: UNIQUE), build_start_date: Datetime, estimated_completion_date: Date, actual_completion_date: Datetime, current_status: String, customer_order_id: String }. Relationships: (:AircraftBuild)-[:IS_MODEL]->(:AircraftModel {model_id}), (:AircraftBuild)-[:ASSEMBLED_ON]->(:AssemblyLine {line_id}). Index on build_id, serial_number, current_status.
Node Label ':Employee'. Properties: { employee_id: String (Constraint: UNIQUE), first_name: String, last_name: String, job_title: String, skill_certifications: String[], hire_date: Date, employment_status: String }. Relationships: (:Employee)-[:ASSIGNED_TO]->(:AssemblyLine {line_id}), (:Employee)-[:REPORTS_TO]->(:Employee {employee_id as supervisor_id}). Index on employee_id.
Node Label ':InventoryBatch'. Properties: { inventory_record_id: String (Constraint: UNIQUE), quantity: Integer, location_warehouse: String, location_bin: String, received_date: Datetime, expiry_date: Date, batch_number: String, last_updated: Datetime }. Relationship: (:InventoryBatch)-[:IS_INSTANCE_OF]->(:Component {component_id}). Index on inventory_record_id, component_id.
|
[
{
"role": "user",
"content": "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;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )
|
[
{
"role": "user",
"content": "Show me all contracts deployed on the 'ethereum' network along with their deployer addresses and the count of events emitted by each contract, sorted by event count in descending order."
},
{
"role": "assistant",
"content": "SELECT c.address, c.deployer_address, COUNT(e.event_id) AS event_count FROM web3.contracts c LEFT JOIN web3.events e ON c.contract_id = e.contract_id WHERE c.network_id = 'ethereum' GROUP BY c.address, c.deployer_address ORDER BY event_count DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.contracts (
contract_id character varying(64) NOT NULL, -- unique identifier for the contract
address character varying(128) NOT NULL, -- address of the deployed contract
abi text NOT NULL, -- application binary interface of the contract
bytecode text NOT NULL, -- bytecode of the contract
deployer_address character varying(128) NOT NULL, -- address of the deployer
deployed_at timestamp NOT NULL, -- time when the contract was deployed
network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed
status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)
PRIMARY KEY (contract_id)
)
CREATE TABLE web3.events (
event_id character varying(64) NOT NULL, -- unique identifier for the event
contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event
event_name character varying(128) NOT NULL, -- name of the event
data text NOT NULL, -- data payload of the event
emitted_at timestamp NOT NULL, -- time when the event was emitted
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event
log_index integer NOT NULL, -- index of the event log in the transaction
PRIMARY KEY (event_id)
)
|
[
{
"role": "user",
"content": "For each application, show the application ID, the full name of the assigned employee, and the name of the service applied for."
},
{
"role": "assistant",
"content": "SELECT a.application_id, CONCAT(e.first_name, ' ', e.last_name) AS employee_full_name, s.service_name\nFROM government_services.applications a\nLEFT JOIN government_services.employees e ON a.assigned_employee_id = e.employee_id\nJOIN government_services.services s ON a.service_id = s.service_id;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.citizens (
citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen
national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
date_of_birth date NOT NULL,
gender character varying(20),
primary_address text NOT NULL, -- full primary residential address
contact_email character varying(128) UNIQUE,
contact_phone character varying(32),
registration_date timestamp NOT NULL, -- when the citizen profile was created
is_verified boolean DEFAULT false, -- whether identity has been officially verified
PRIMARY KEY (citizen_id)
)
CREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )
CREATE TABLE government_services.applications (
application_id character varying(64) NOT NULL, -- unique identifier for the application
citizen_id character varying(64) NOT NULL, -- FK to citizens table
service_id character varying(64) NOT NULL, -- FK to services table
submitted_at timestamp NOT NULL, -- time the application was submitted
status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info
last_updated_at timestamp NOT NULL, -- time the status or details last changed
assigned_employee_id character varying(64), -- FK to employees table (optional)
decision_date date, -- date when a final decision was made
notes text, -- internal notes or citizen-provided comments
reference_number character varying(100) UNIQUE, -- publicly visible reference number
PRIMARY KEY (application_id)
)
CREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )
CREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )
CREATE TABLE government_services.employees (
employee_id character varying(64) NOT NULL, -- unique identifier for the government employee
agency_id character varying(64) NOT NULL, -- FK to agencies table
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
job_title character varying(150) NOT NULL,
department character varying(100),
work_email character varying(128) NOT NULL UNIQUE,
work_phone character varying(32),
hire_date date NOT NULL,
termination_date date, -- null if currently employed
access_level character varying(50), -- Role or permission level
manager_employee_id character varying(64), -- FK to self for reporting structure
PRIMARY KEY (employee_id)
)
CREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )
CREATE TABLE government_services.appointments ( appointment_id text 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 )
|
[
{
"role": "user",
"content": "Show each service's name along with the total number of appointments scheduled and the number of unique locations these appointments are scheduled at."
},
{
"role": "assistant",
"content": "SELECT s.service_name, COUNT(a.application_id) AS appointment_count, COUNT(DISTINCT ap.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.appointments ap ON a.application_id = ap.application_id\nGROUP BY s.service_name;"
},
{
"role": "user",
"content": "I got an error: relation 'appointments' does not exist."
},
{
"role": "assistant",
"content": "-- The appointments table is not present in the provided schema. If you want to count by another join, perhaps by documents or payments, please specify.\n-- Alternatively, do you want appointment information replaced with application submissions per service and their associated location from service_locations?\nSELECT s.service_name, COUNT(a.application_id) AS application_count, COUNT(DISTINCT sl.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.service_locations sl ON s.agency_id = sl.agency_id\nGROUP BY s.service_name;"
},
{
"role": "user",
"content": "Show only those services where application_count is greater than 50."
},
{
"role": "assistant",
"content": "SELECT s.service_name, COUNT(a.application_id) AS application_count, COUNT(DISTINCT sl.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.service_locations sl ON s.agency_id = sl.agency_id\nGROUP BY s.service_name\nHAVING COUNT(a.application_id) > 50;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.citizens (
citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen
national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
date_of_birth date NOT NULL,
gender character varying(20),
primary_address text NOT NULL, -- full primary residential address
contact_email character varying(128) UNIQUE,
contact_phone character varying(32),
registration_date timestamp NOT NULL, -- when the citizen profile was created
is_verified boolean DEFAULT false, -- whether identity has been officially verified
PRIMARY KEY (citizen_id)
)
CREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )
CREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )
CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )
CREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp )
CREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )
CREATE TABLE government_services.service_locations (
location_id character varying(64) NOT NULL, -- unique identifier for the physical location
agency_id character varying(64) NOT NULL, -- FK to agencies table
location_name character varying(200), -- e.g., Downtown DMV Office
address text NOT NULL,
city character varying(100),
state character varying(50),
postal_code character varying(20),
latitude numeric(9, 6),
longitude numeric(9, 6),
operating_hours text, -- description of opening times
contact_phone character varying(32),
is_accessible boolean, -- accessibility information (e.g., wheelchair access)
PRIMARY KEY (location_id)
)
CREATE TABLE government_services.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 )
|
[
{
"role": "user",
"content": "Show me all lawyers' full names, their bar number, and if they are partners, the full name of another partner from their firm."
},
{
"role": "assistant",
"content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1;"
},
{
"role": "user",
"content": "Only include lawyers who have an email address specified."
},
{
"role": "assistant",
"content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1\nWHERE l1.email IS NOT NULL AND l1.email <> '';"
},
{
"role": "user",
"content": "Actually, restrict it to lawyers hired in or after 2023."
},
{
"role": "assistant",
"content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1\nWHERE l1.email IS NOT NULL AND l1.email <> '' AND l1.hire_date >= '2023-01-01';"
},
{
"role": "user",
"content": "Sort the results by the lawyer's last name in descending order."
},
{
"role": "assistant",
"content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1\nWHERE l1.email IS NOT NULL AND l1.email <> '' AND l1.hire_date >= '2023-01-01'\nORDER BY l1.last_name DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )
|
[
{
"role": "user",
"content": "List all pairs of diagnoses that belong to the same medical record. Show record_id, diagnosis_id from the first entry as diag1_id, and diagnosis_id from the second entry as diag2_id."
},
{
"role": "assistant",
"content": "SELECT d1.record_id,\n d1.diagnosis_id AS diag1_id,\n d2.diagnosis_id AS diag2_id\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.record_id = d2.record_id\n AND d1.diagnosis_id < d2.diagnosis_id;"
},
{
"role": "user",
"content": "Only include pairs where both diagnoses are chronic."
},
{
"role": "assistant",
"content": "SELECT d1.record_id,\n d1.diagnosis_id AS diag1_id,\n d2.diagnosis_id AS diag2_id\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.record_id = d2.record_id\n AND d1.diagnosis_id < d2.diagnosis_id\nWHERE d1.is_chronic = TRUE\n AND d2.is_chronic = TRUE;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE healthcare.diagnoses (
diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry
record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry
patient_id character varying(64) NOT NULL, -- FK to patients table
doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)
diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)
code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used
description text, -- textual description of the diagnosis
diagnosis_date date NOT NULL, -- date the diagnosis was made
status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out
is_chronic boolean DEFAULT false, -- flag for chronic conditions
PRIMARY KEY (diagnosis_id)
)
|
[
{
"role": "user",
"content": "How many hashtags have been created in March 2024?"
},
{
"role": "assistant",
"content": "```sql\nSELECT COUNT(*) AS march_2024_hashtag_count\nFROM social_media.hashtags\nWHERE created_at >= '2024-03-01'\n AND created_at < '2024-04-01';\n```"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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 )
CREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )
CREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )
CREATE 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 )
|
[
{
"role": "user",
"content": "Could you list each game title along with its developer's name and the total number of servers hosting it?"
},
{
"role": "assistant",
"content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nLEFT JOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nLEFT JOIN gaming_technology.servers s ON g.game_id = s.game_id\nGROUP BY g.title, d.name;"
},
{
"role": "user",
"content": "Actually, please include only servers with status = 'online' and exclude games with zero online servers."
},
{
"role": "assistant",
"content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nJOIN gaming_technology.servers s ON g.game_id = s.game_id\nWHERE s.status = 'online'\nGROUP BY g.title, d.name;"
},
{
"role": "user",
"content": "I want to see only developers based in 'USA'."
},
{
"role": "assistant",
"content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nJOIN gaming_technology.servers s ON g.game_id = s.game_id AND s.status = 'online'\nWHERE d.country = 'USA'\nGROUP BY g.title, d.name;"
},
{
"role": "user",
"content": "Finally, sort the results by server_count in descending order."
},
{
"role": "assistant",
"content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nJOIN gaming_technology.servers s ON g.game_id = s.game_id AND s.status = 'online'\nWHERE d.country = 'USA'\nGROUP BY g.title, d.name\nORDER BY server_count DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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 )
CREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )
CREATE TABLE gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )
CREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )
CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )
CREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )
CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid, player_id uuid, item_id uuid, quantity integer, acquired_at timestamp with time zone, instance_data jsonb )
|
[
{
"role": "user",
"content": "Show me all events emitted by contracts where the event name contains 'Approval', along with the contract ID and transaction ID, sorted by emitted timestamp in descending order."
},
{
"role": "assistant",
"content": "SELECT event_id, contract_id, event_name, transaction_id, emitted_at FROM web3.events WHERE event_name LIKE '%Approval%' ORDER BY emitted_at DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.events (
event_id character varying(64) NOT NULL, -- unique identifier for the event
contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event
event_name character varying(128) NOT NULL, -- name of the event
data text NOT NULL, -- data payload of the event
emitted_at timestamp NOT NULL, -- time when the event was emitted
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event
log_index integer NOT NULL, -- index of the event log in the transaction
PRIMARY KEY (event_id)
)
|
[
{
"role": "user",
"content": "Show the names of all insurance plans and the number of patients enrolled in each plan."
},
{
"role": "assistant",
"content": "SELECT ip.plan_name, COUNT(pi.patient_id) AS enrolled_patients FROM healthcare.insurance_plans ip JOIN healthcare.patient_insurance pi ON ip.plan_id = pi.plan_id GROUP BY ip.plan_name;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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) )
CREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )
CREATE TABLE healthcare.diagnoses (
diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry
record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry
patient_id character varying(64) NOT NULL, -- FK to patients table
doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)
diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)
code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used
description text, -- textual description of the diagnosis
diagnosis_date date NOT NULL, -- date the diagnosis was made
status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out
is_chronic boolean DEFAULT false, -- flag for chronic conditions
PRIMARY KEY (diagnosis_id)
)
CREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )
CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
CREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )
|
[
{
"role": "user",
"content": "For each guest, calculate their total spending on delivered service orders and the total number of those orders."
},
{
"role": "assistant",
"content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.total_price) AS total_spent,\n COUNT(*) AS total_orders\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.status = 'delivered'\nGROUP BY g.guest_id, full_name;"
},
{
"role": "user",
"content": "I need the breakdown by month for the current year. Show guest ID, month, total spent, and total orders."
},
{
"role": "assistant",
"content": "SELECT so.guest_id,\n DATE_TRUNC('month', so.delivery_timestamp) AS month,\n SUM(so.total_price) AS total_spent,\n COUNT(*) AS total_orders\nFROM hospitality_technology.service_orders so\nWHERE so.status = 'delivered'\n AND so.delivery_timestamp >= '2024-01-01'\n AND so.delivery_timestamp < '2025-01-01'\nGROUP BY so.guest_id, month\nORDER BY month;"
},
{
"role": "user",
"content": "Also include the guest’s email and only show months where total spent is greater than 500."
},
{
"role": "assistant",
"content": "SELECT sub.guest_id,\n g.email,\n sub.month,\n sub.total_spent,\n sub.total_orders\nFROM (\n SELECT so.guest_id,\n DATE_TRUNC('month', so.delivery_timestamp) AS month,\n SUM(so.total_price) AS total_spent,\n COUNT(*) AS total_orders\n FROM hospitality_technology.service_orders so\n WHERE so.status = 'delivered'\n AND so.delivery_timestamp >= '2024-01-01'\n AND so.delivery_timestamp < '2025-01-01'\n GROUP BY so.guest_id, month\n) sub\nJOIN hospitality_technology.guests g\n ON sub.guest_id = g.guest_id\nWHERE sub.total_spent > 500\nORDER BY sub.month;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )
CREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )
|
[
{
"role": "user",
"content": "Find all pairs of overlapping payment periods for the same customer. Return customer_id, first payment_id as payment1_id, second payment_id as payment2_id, and both periods' start and end dates."
},
{
"role": "assistant",
"content": "SELECT p1.customer_id,\n p1.payment_id AS payment1_id,\n p2.payment_id AS payment2_id,\n p1.payment_period_start AS start1,\n p1.payment_period_end AS end1,\n p2.payment_period_start AS start2,\n p2.payment_period_end AS end2\nFROM insurance.premium_payments p1\nJOIN insurance.premium_payments p2\n ON p1.customer_id = p2.customer_id\n AND p1.payment_id < p2.payment_id\n -- periods overlap\n AND p1.payment_period_start <= p2.payment_period_end\n AND p2.payment_period_start <= p1.payment_period_end;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE insurance.premium_payments (
payment_id character varying(64) NOT NULL, -- unique identifier for the payment
policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)
customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)
payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received
amount_paid numeric(12, 2) NOT NULL, -- amount of the payment
payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check
transaction_reference character varying(128) UNIQUE, -- reference from payment processor
due_date date, -- due date for this payment installment
payment_period_start date, -- start date of the period this payment covers
payment_period_end date, -- end date of the period this payment covers
status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded
PRIMARY KEY (payment_id)
)
|
[
{
"role": "user",
"content": "Show me all home loans (loan_id, principal_amount, interest_rate) where the current principal balance is more than 75% of the original principal amount, along with the account_id and employee details (first_name, last_name) of the employee who processed the loan application."
},
{
"role": "assistant",
"content": "SELECT l.loan_id, l.principal_amount, l.interest_rate, l.account_id, e.first_name, e.last_name FROM financial_services.loans l JOIN financial_services.employees e ON l.account_id = e.employee_id WHERE l.loan_type = 'Home' AND l.current_principal_balance > (l.principal_amount * 0.75)"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE financial_services.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 )
CREATE 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 )
CREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )
CREATE TABLE financial_services.employees ( employee_id.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 )
CREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )
|
[
{
"role": "user",
"content": "List all transfers of the token named 'Wrapped Ether', showing the transfer id, token id, value, and the contract address of the token."
},
{
"role": "assistant",
"content": "SELECT tt.transfer_id, tt.token_id, tt.value, t.contract_address\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id\nWHERE t.token_name = 'Wrapped Ether';"
},
{
"role": "user",
"content": "Actually, can you also include the username of the user who owns the sender address, if such a user exists?"
},
{
"role": "assistant",
"content": "SELECT tt.transfer_id, tt.token_id, tt.value, t.contract_address, u.username\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id\nLEFT JOIN web3.users u ON tt.from_address = (\n SELECT w.address FROM web3.wallets w WHERE w.user_id = u.user_id AND w.address = tt.from_address LIMIT 1\n)\nWHERE t.token_name = 'Wrapped Ether';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )
CREATE 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) )
CREATE 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) )
CREATE 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) )
|
[
{
"role": "user",
"content": "Find tokens with a 24-hour DEX trading volume greater than $500,000. For these tokens, display their symbol, chain, the 24h volume from the DEX pool, and the narrative category they belong to from the smart money inflow data."
},
{
"role": "assistant",
"content": "SELECT DISTINCT t1.token_symbol, t1.chain, t1.volume_24h, t2.narrative FROM token_dexpool_info AS t1 JOIN smart_money_token_inflow AS t2 ON t1.token_symbol = t2.token_symbol AND t1.chain = t2.chain WHERE t1.volume_24h > 500000;"
},
{
"role": "user",
"content": "Can you filter the results to only include tokens on the 'Polygon' or 'Arbitrum' chains?"
},
{
"role": "assistant",
"content": "SELECT DISTINCT t1.token_symbol, t1.chain, t1.volume_24h, t2.narrative FROM token_dexpool_info AS t1 JOIN smart_money_token_inflow AS t2 ON t1.token_symbol = t2.token_symbol AND t1.chain = t2.chain WHERE t1.volume_24h > 500000 AND t1.chain IN ('Polygon', 'Arbitrum');"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )
CREATE TABLE token_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) )
"CREATE TABLE cex_token_balance (",
"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp",
"chain character varying(128) NOT NULL, -- the chain that the token resides",
"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX",
"exchange character varying(512) NOT NULL, -- a centralized exchange name",
"token_address character varying(128) NOT NULL, -- token contract address",
"token_symbol character varying(512), --token symbol",
"balance numeric(38,10), -- token balance",
"usd_value numeric(38,14), -- value of the token held in USD",
"price double precision, --price of the token in USD",
",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));"
CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )
|
[
{
"role": "user",
"content": "List the first name, last name, and hire date of all lawyers who are partners."
},
{
"role": "assistant",
"content": "SELECT first_name , last_name , hire_date FROM legal_services.lawyers WHERE is_partner = TRUE"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE legal_services.lawyers (
lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer
first_name character varying(100) NOT NULL, -- lawyer's first name
last_name character varying(100) NOT NULL, -- lawyer's last name
bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number
firm_id character varying(64), -- FK to law_firms table
email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email
phone character varying(32), -- lawyer's contact phone number
specialization text, -- areas of legal expertise
hire_date timestamp NOT NULL, -- date the lawyer was hired or joined
is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner
PRIMARY KEY (lawyer_id)
)
|
[
{
"role": "user",
"content": "Show a list of all wallet addresses along with the user_id who owns them, sorted by the wallet creation time."
},
{
"role": "assistant",
"content": "SELECT user_id, address FROM web3.wallets ORDER BY created_at;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.wallets (
wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet
user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet
address character varying(128) NOT NULL, -- address of the wallet
private_key text NOT NULL, -- private key of the wallet
created_at timestamp NOT NULL, -- time when the wallet was created
PRIMARY KEY (wallet_id)
)
|
[
{
"role": "user",
"content": "特定のコンポーネントの在庫情報を取得したいです。コンポーネントIDと在庫数量、倉庫の場所を含めてください。"
},
{
"role": "assistant",
"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id';"
},
{
"role": "user",
"content": "さらに、受け取り日が2022年以降の記録だけを表示するようにできますか?"
},
{
"role": "assistant",
"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01';"
},
{
"role": "user",
"content": "在庫数量が100未満のものだけに絞り込むことは可能ですか?"
},
{
"role": "assistant",
"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01' AND quantity < 100;"
},
{
"role": "user",
"content": "最後に、受け取り日を新しい順に並べ替えてください。"
},
{
"role": "assistant",
"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01' AND quantity < 100 ORDER BY received_date DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
Index 'component_inventory'. Mapping: { properties: { inventory_record_id: { type: 'keyword' }, component_id: { type: 'keyword' }, quantity: { type: 'integer' }, location_warehouse: { type: 'keyword' }, location_bin: { type: 'keyword' }, received_date: { type: 'date' }, expiry_date: { type: 'date' }, batch_number: { type: 'keyword' }, last_updated: { type: 'date' } } }. Document _id can be inventory_record_id.
|
[
{
"role": "user",
"content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses."
},
{
"role": "assistant",
"content": "SELECT name, symbol, address FROM token_prices_latest WHERE price BETWEEN 1 AND 10 AND blockchain = 'ethereum';"
},
{
"role": "user",
"content": "I think there's an error in your query - it should be joining with sui_coins_metadata on coin_type not address. Also, can you add the current price to the results?"
},
{
"role": "assistant",
"content": "SELECT scm.name, scm.symbol, scm.coin_type, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.coin_type = tpl.address WHERE tpl.price BETWEEN 1 AND 10;"
},
{
"role": "user",
"content": "Now filter these results to only show tokens with decimals equal to 18 and sort by name alphabetically."
},
{
"role": "assistant",
"content": "SELECT scm.name, scm.symbol, scm.coin_type, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.coin_type = tpl.address WHERE tpl.price BETWEEN 1 AND 10 AND scm.decimals = 18 ORDER BY scm.name ASC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE erc1155_approval_for_all (
block_number bigint NOT NULL, -- Block number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction
transaction_index integer NOT NULL, -- Index of the transaction within the block
transaction_hash varchar(66) NOT NULL, -- Transaction hash
log_index integer NOT NULL, -- Log index
contract_address varchar(42) NOT NULL -- Event contract address
)
CREATE TABLE nft_holder_historical (
block_number bigint NOT NULL, -- Block number containing the transaction
contract_address varchar NOT NULL, -- Event contract address
wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)
token_id varchar NOT NULL, -- NFT token id
contract_type varchar NOT NULL, -- NFT contract type
amount varchar NOT NULL, -- The quantity held in the wallet
pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200))
)
CREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )
CREATE TABLE sui_nfts (
object_id varchar NOT NULL, -- object id of the nft
status varchar NOT NULL, -- status of the package, exists or deleted
collection_type varchar NOT NULL, -- collection type of the nft, eg. 0x...123::avatars::Avatar
package_id varchar NOT NULL, -- which package the nft belongs to, eg. 0x...123::avatars belongs to 0x...123
previous_transaction varchar NOT NULL, -- previous transaction of the nft
display varchar NOT NULL, -- nft metadata json object
owner varchar NOT NULL, -- nft owner
name varchar NOT NULL -- nft name
)
CREATE TABLE nft_metadata (
blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract
contract_address varchar NOT NULL, -- Contract address(with bloom filter)
token_id varchar NOT NULL, -- The number of the token
contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract
erc_type varchar NOT NULL, -- The type of token
amount bigint NOT NULL, -- amount fields for the functionType in contract
minter varchar NOT NULL, -- minter fields for the functionType in contract
owner varchar NOT NULL, -- owner fields for the functionType in contract
mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract
mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract
mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract
mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract
token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract
metadata varchar NOT NULL, -- metadata fields for the functionType in contract
name varchar NOT NULL, -- name fields for the functionType in contract
image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract
traits varchar NOT NULL, -- traits fields for the functionType in contract
updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract
status varchar NOT NULL, -- status fields for the functionType in contract
rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract
rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract
unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract
pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30))
)
CREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE token_balances (
block_number bigint NOT NULL, -- Block number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction
tick varchar NOT NULL, -- Token tick
wallet_address varchar(42) NOT NULL, -- Address of owner
total_supply decimal(38,0) NOT NULL, -- Max supply
amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height
)
CREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )
|
[
{
"role": "user",
"content": "What is the total USD value held by all centralized exchanges (CEX) for the token with the symbol 'BTC'?"
},
{
"role": "assistant",
"content": "SELECT SUM(usd_value) AS total_btc_cex_value FROM cex_token_balance WHERE token_symbol = 'BTC';"
},
{
"role": "user",
"content": "Can you break down the total USD value for 'BTC' held by CEXes by chain?"
},
{
"role": "assistant",
"content": "SELECT chain, SUM(usd_value) AS total_btc_cex_value FROM cex_token_balance WHERE token_symbol = 'BTC' GROUP BY chain ORDER BY total_btc_cex_value DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )
CREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )
CREATE TABLE 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 )
CREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp chain character varying(128) NOT NULL, -- the chain that the token resides address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX exchange character varying(512) NOT NULL, -- a centralized exchange name token_address character varying(128) NOT NULL, -- token contract address token_symbol character varying(512), --token symbol balance numeric(38,10), -- token balance usd_value numeric(38,14), -- value of the token held in USD price double precision, --price of the token in USD ,PRIMARY KEY (snapshot_time, exchange, address, chain, token_address) )
CREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )
CREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )
CREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )
|
[
{
"role": "user",
"content": "List the plan_id, plan_name, and plan_type for all insurance plans where the insurance_provider is 'Humana'."
},
{
"role": "assistant",
"content": "SELECT\n plan_id,\n plan_name,\n plan_type\nFROM healthcare.insurance_plans\nWHERE\n insurance_provider = 'Humana';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
CREATE TABLE healthcare.appointments (
appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment
patient_id character varying(64) NOT NULL, -- FK to patients table
doctor_id character varying(64) NOT NULL, -- FK to doctors table
appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment
duration_minutes integer NOT NULL, -- expected duration in minutes
reason text, -- reason for the visit
status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show
location_id character varying(64), -- FK to a potential locations/clinics table
notes text, -- notes related to scheduling
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (appointment_id)
)
CREATE TABLE healthcare.medical_records (
record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry
patient_id character varying(64) NOT NULL, -- FK to patients table
appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)
doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)
record_date timestamp with time zone NOT NULL, -- date the record/observation was made
chief_complaint text, -- patient's primary reason for visit
present_illness_history text, -- detailed history of the current issue
past_medical_history text, -- relevant past conditions/surgeries
physical_examination_notes text, -- findings from the physical exam
assessment text, -- doctor's assessment/diagnosis summary
treatment_plan text, -- planned course of action
vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (record_id)
)
CREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )
CREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )
CREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )
CREATE TABLE healthcare.insurance_plans (
plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan
plan_name character varying(200) NOT NULL, -- name of the insurance plan
insurance_provider character varying(100) NOT NULL, -- name of the insurance company
plan_type character varying(50), -- e.g., PPO, HMO, EPO
contact_phone character varying(20), -- provider contact number
website character varying(255), -- provider website
PRIMARY KEY (plan_id)
)
|
[
{
"role": "user",
"content": "Can you provide a list of all medical records created by doctors for patients who are associated with 'PPO' type insurance plans? I need the record ID, patient ID, doctor ID, record date, and insurance plan name."
},
{
"role": "assistant",
"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.patient_id IS NOT NULL -- placeholder JOIN, fix below if you have a patient-insurance mapping table\nWHERE ip.plan_type = 'PPO';"
},
{
"role": "user",
"content": "The SQL seems off because there's no direct mapping between patients and insurance_plans in the schema. Can you adjust the query so that it only lists medical records with the plan details if the doctor creating the record has a contact phone number that matches the plan's contact_phone? Still need the same output columns."
},
{
"role": "assistant",
"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL;"
},
{
"role": "user",
"content": "Actually, please sort the results by record_date in descending order and return only the latest 20 records."
},
{
"role": "assistant",
"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL\nORDER BY mr.record_date DESC\nLIMIT 20;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE healthcare.medical_records (
record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry
patient_id character varying(64) NOT NULL, -- FK to patients table
appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)
doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)
record_date timestamp with time zone NOT NULL, -- date the record/observation was made
chief_complaint text, -- patient's primary reason for visit
present_illness_history text, -- detailed history of the current issue
past_medical_history text, -- relevant past conditions/surgeries
physical_examination_notes text, -- findings from the physical exam
assessment text, -- doctor's assessment/diagnosis summary
treatment_plan text, -- planned course of action
vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (record_id)
)
CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
|
[
{
"role": "user",
"content": "List each username with how many users they follow and how many users follow them."
},
{
"role": "assistant",
"content": "SELECT u.username,\n COALESCE(following.following_count, 0) AS following_count,\n COALESCE(followers.followers_count, 0) AS followers_count\nFROM social_media.users u\nLEFT JOIN (\n SELECT follower_user_id, COUNT(*) AS following_count\n FROM social_media.follows\n GROUP BY follower_user_id\n) AS following\n ON u.user_id = following.follower_user_id\nLEFT JOIN (\n SELECT following_user_id, COUNT(*) AS followers_count\n FROM social_media.follows\n GROUP BY following_user_id\n) AS followers\n ON u.user_id = followers.following_user_id;"
},
{
"role": "user",
"content": "Also include only those users who follow more people than follow them."
},
{
"role": "assistant",
"content": "SELECT u.username,\n COALESCE(following.following_count, 0) AS following_count,\n COALESCE(followers.followers_count, 0) AS followers_count\nFROM social_media.users u\nLEFT JOIN (\n SELECT follower_user_id, COUNT(*) AS following_count\n FROM social_media.follows\n GROUP BY follower_user_id\n) AS following\n ON u.user_id = following.follower_user_id\nLEFT JOIN (\n SELECT following_user_id, COUNT(*) AS followers_count\n FROM social_media.follows\n GROUP BY following_user_id\n) AS followers\n ON u.user_id = followers.following_user_id\nWHERE COALESCE(following.following_count, 0) > COALESCE(followers.followers_count, 0);"
},
{
"role": "user",
"content": "Sort the results by the difference between following_count and followers_count in descending order, and alias this difference as difference_count."
},
{
"role": "assistant",
"content": "SELECT u.username,\n COALESCE(following.following_count, 0) AS following_count,\n COALESCE(followers.followers_count, 0) AS followers_count,\n (COALESCE(following.following_count, 0) - COALESCE(followers.followers_count, 0)) AS difference_count\nFROM social_media.users u\nLEFT JOIN (\n SELECT follower_user_id, COUNT(*) AS following_count\n FROM social_media.follows\n GROUP BY follower_user_id\n) AS following\n ON u.user_id = following.follower_user_id\nLEFT JOIN (\n SELECT following_user_id, COUNT(*) AS followers_count\n FROM social_media.follows\n GROUP BY following_user_id\n) AS followers\n ON u.user_id = followers.following_user_id\nWHERE (COALESCE(following.following_count, 0) - COALESCE(followers.followers_count, 0)) > 0\nORDER BY difference_count DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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 )
CREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id text PRIMARY KEY, post_id text, hashtag_id text )
CREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )
CREATE 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 )
|
[
{
"role": "user",
"content": "List the username and email of users whose first wallet creation date is the same day as their user registration date."
},
{
"role": "assistant",
"content": "SELECT u.username, u.email FROM web3.users u JOIN (SELECT user_id, MIN(created_at) as first_wallet_created_at FROM web3.wallets GROUP BY user_id) w ON u.user_id = w.user_id WHERE DATE(u.created_at) = DATE(w.first_wallet_created_at);"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.events (
event_id character varying(64) NOT NULL, -- unique identifier for the event
contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event
event_name character varying(128) NOT NULL, -- name of the event
data text NOT NULL, -- data payload of the event
emitted_at timestamp NOT NULL, -- time when the event was emitted
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event
log_index integer NOT NULL, -- index of the event log in the transaction
PRIMARY KEY (event_id)
)
CREATE TABLE web3.tokens (
token_id character varying(64) NOT NULL, -- unique identifier for the token
contract_address character varying(128) NOT NULL, -- address of the token contract
token_name character varying(128) NOT NULL, -- name of the token
token_symbol character varying(32) NOT NULL, -- symbol of the token
decimals integer NOT NULL, -- number of decimals for the token
total_supply numeric(38,14) NOT NULL, -- total supply of the token
PRIMARY KEY (token_id)
)
CREATE TABLE web3.wallets (
wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet
user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet
address character varying(128) NOT NULL, -- address of the wallet
private_key text NOT NULL, -- private key of the wallet
created_at timestamp NOT NULL, -- time when the wallet was created
PRIMARY KEY (wallet_id)
)
CREATE TABLE web3.users (
user_id character varying(64) NOT NULL, -- unique identifier for the user
username character varying(128) NOT NULL, -- username of the user
email character varying(128) NOT NULL, -- email address of the user
password_hash text NOT NULL, -- hashed password of the user
created_at timestamp NOT NULL, -- time when the user account was created
PRIMARY KEY (user_id)
)
|
[
{
"role": "user",
"content": "List the first name and last name of the driver and the license plate of the vehicle used for each trip."
},
{
"role": "assistant",
"content": "SELECT T1.first_name , T1.last_name , T3.license_plate FROM transportation.drivers AS T1 JOIN transportation.trips AS T2 ON T1.driver_id = T2.driver_id JOIN transportation.vehicles AS T3 ON T2.vehicle_id = T3.vehicle_id"
},
{
"role": "user",
"content": "Now, restrict this list to only include trips where the vehicle's fuel type is 'Electric'."
},
{
"role": "assistant",
"content": "SELECT T1.first_name , T1.last_name , T3.license_plate FROM transportation.drivers AS T1 JOIN transportation.trips AS T2 ON T1.driver_id = T2.driver_id JOIN transportation.vehicles AS T3 ON T2.vehicle_id = T3.vehicle_id WHERE T3.fuel_type = 'Electric'"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )
CREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )
CREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )
CREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )
CREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )
CREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )
CREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )
CREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )
|
[
{
"role": "user",
"content": "List the full name and bar number of all lawyers who were hired before 2015."
},
{
"role": "assistant",
"content": "SELECT first_name || ' ' || last_name AS lawyer_full_name, bar_number\nFROM legal_services.lawyers\nWHERE hire_date < '2015-01-01';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )
CREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, bar_number character varying(64) UNIQUE NOT NULL, firm_id character varying(64), email character varying(128) UNIQUE NOT NULL, phone character varying(32), specialization text, hire_date timestamp NOT NULL, is_partner boolean DEFAULT false, PRIMARY KEY (lawyer_id) )
CREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )
CREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )
|
[
{
"role": "user",
"content": "Show me the notification ID, recipient user ID, and notification type for notifications received by users that user 'user123' is following."
},
{
"role": "assistant",
"content": "SELECT n.notification_id, n.recipient_user_id, n.notification_type FROM social_media.notifications AS n JOIN social_media.follows AS f ON n.recipient_user_id = f.following_user_id WHERE f.follower_user_id = 'user123';"
},
{
"role": "user",
"content": "Filter this list to only include notifications created after '2024-06-01' and also show the notification creation time."
},
{
"role": "assistant",
"content": "SELECT n.notification_id, n.recipient_user_id, n.notification_type, n.created_at FROM social_media.notifications AS n JOIN social_media.follows AS f ON n.recipient_user_id = f.following_user_id WHERE f.follower_user_id = 'user123' AND n.created_at >= '2024-06-01';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )
CREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )
CREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )
CREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )
|
[
{
"role": "user",
"content": "Show me all pairs of patients who share the same emergency contact phone, including both patient IDs, their names, and the shared emergency contact phone."
},
{
"role": "assistant",
"content": "SELECT p1.patient_id,\n p1.first_name,\n p1.last_name,\n p2.patient_id AS other_patient_id,\n p2.first_name AS other_first_name,\n p2.last_name AS other_last_name,\n p1.emergency_contact_phone\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_phone = p2.emergency_contact_phone\n AND p1.patient_id < p2.patient_id;"
},
{
"role": "user",
"content": "Only include those pairs where both emergency_contact_name values are not null."
},
{
"role": "assistant",
"content": "SELECT p1.patient_id,\n p1.first_name,\n p1.last_name,\n p2.patient_id AS other_patient_id,\n p2.first_name AS other_first_name,\n p2.last_name AS other_last_name,\n p1.emergency_contact_phone\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_phone = p2.emergency_contact_phone\n AND p1.patient_id < p2.patient_id\nWHERE p1.emergency_contact_name IS NOT NULL\n AND p2.emergency_contact_name IS NOT NULL;"
},
{
"role": "user",
"content": "Also exclude any pairs where the shared emergency contact phone matches the patient's own phone_number."
},
{
"role": "assistant",
"content": "SELECT p1.patient_id,\n p1.first_name,\n p1.last_name,\n p2.patient_id AS other_patient_id,\n p2.first_name AS other_first_name,\n p2.last_name AS other_last_name,\n p1.emergency_contact_phone\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_phone = p2.emergency_contact_phone\n AND p1.patient_id < p2.patient_id\nWHERE p1.emergency_contact_name IS NOT NULL\n AND p2.emergency_contact_name IS NOT NULL\n AND p1.emergency_contact_phone <> p1.phone_number\n AND p2.emergency_contact_phone <> p2.phone_number;"
},
{
"role": "user",
"content": "Finally, order the results by the shared emergency contact phone ascending and limit to the first 50 pairs."
},
{
"role": "assistant",
"content": "SELECT p1.patient_id,\n p1.first_name,\n p1.last_name,\n p2.patient_id AS other_patient_id,\n p2.first_name AS other_first_name,\n p2.last_name AS other_last_name,\n p1.emergency_contact_phone\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_phone = p2.emergency_contact_phone\n AND p1.patient_id < p2.patient_id\nWHERE p1.emergency_contact_name IS NOT NULL\n AND p2.emergency_contact_name IS NOT NULL\n AND p1.emergency_contact_phone <> p1.phone_number\n AND p2.emergency_contact_phone <> p2.phone_number\nORDER BY p1.emergency_contact_phone ASC\nLIMIT 50;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
|
[
{
"role": "user",
"content": "What is the average number of wallets each user owns?"
},
{
"role": "assistant",
"content": "SELECT\n AVG(wallet_count) AS avg_wallets_per_user\nFROM (\n SELECT user_id, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY user_id\n) AS sub;"
},
{
"role": "user",
"content": "Actually, calculate the average only for users who own more than one wallet."
},
{
"role": "assistant",
"content": "SELECT\n AVG(wallet_count) AS avg_wallets_per_user\nFROM (\n SELECT user_id, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY user_id\n HAVING COUNT(*) > 1\n) AS sub;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
|
[
{
"role": "user",
"content": "Show me all customers who have missing contact information (either phone number or email is null), along with their state and city."
},
{
"role": "assistant",
"content": "SELECT first_name, last_name, state, city FROM insurance.customers WHERE phone_number IS NULL OR email IS NULL;"
},
{
"role": "user",
"content": "Now filter these to only show customers from Florida or New York who were created in the last year."
},
{
"role": "assistant",
"content": "SELECT first_name, last_name, state, city FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '1 year';"
},
{
"role": "user",
"content": "I also want to see when these customers were last updated (updated_at field)."
},
{
"role": "assistant",
"content": "SELECT first_name, last_name, state, city, updated_at FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '1 year';"
},
{
"role": "user",
"content": "Finally, order the results by state first, then by the most recently updated customers first."
},
{
"role": "assistant",
"content": "SELECT first_name, last_name, state, city, updated_at FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '1 year' ORDER BY state, updated_at DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE insurance.customers (
customer_id character varying(64) NOT NULL, -- unique identifier for the customer
first_name character varying(100) NOT NULL, -- customer's first name
last_name character varying(100) NOT NULL, -- customer's last name
date_of_birth date NOT NULL, -- customer's date of birth
ssn_hash character varying(128), -- Hashed social security number (or national ID)
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, -- unique email address
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created
updated_at timestamp, -- when the customer record was last updated
status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect
PRIMARY KEY (customer_id)
)
|
[
{
"role": "user",
"content": "For each player, show the player_id and the count of inventory items they acquired with a quantity greater than 1."
},
{
"role": "assistant",
"content": "SELECT player_id, COUNT(inventory_id) AS items_qty_gt_1_count FROM gaming_technology.player_inventory WHERE quantity > 1 GROUP BY player_id;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )
CREATE TABLE gaming_technology.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_id) )
CREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )
CREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )
CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )
|
[
{
"role": "user",
"content": "List usernames and the length of their 'bio' field for users whose 'is_verified' status is true."
},
{
"role": "assistant",
"content": "SELECT username, LENGTH(bio) AS bio_length FROM social_media.users WHERE is_verified IS TRUE;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )
|
[
{
"role": "user",
"content": "List the name and symbol for all assets that do not have a corresponding entry with the key 'website' in the metadata table."
},
{
"role": "assistant",
"content": "SELECT T1.name , T1.symbol FROM trading_platform.assets AS T1 LEFT JOIN trading_platform.metadata AS T2 ON T1.asset_id = T2.asset_id AND T2.key = 'website' WHERE T2.metadata_id IS NULL"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )
CREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )
CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.trades (
trade_id character varying(64) NOT NULL, -- unique identifier for the trade
order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade
buyer_id character varying(64) NOT NULL, -- identifier of the buyer
seller_id character varying(64) NOT NULL, -- identifier of the seller
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade
price numeric(38,14) NOT NULL, -- price per unit of the asset
traded_at timestamp NOT NULL, -- time when the trade was executed
PRIMARY KEY (trade_id)
)
CREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )
CREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )
CREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )
CREATE TABLE trading_platform.metadata (
metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata
asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
key character varying(128) NOT NULL, -- key of the metadata
value text NOT NULL, -- value of the metadata
PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.kyc_audit (
kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit
user_id character varying(64) NOT NULL, -- identifier of the user being audited
status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)
reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed
PRIMARY KEY (kyc_audit_id)
)
|
[
{
"role": "user",
"content": "List the content and sent time for messages sent by user 'U101'."
},
{
"role": "assistant",
"content": "SELECT content, sent_at FROM social_media.messages WHERE sender_user_id = 'U101';"
},
{
"role": "user",
"content": "Could you also include the group name for those messages and only show messages sent in group chats?"
},
{
"role": "assistant",
"content": "SELECT m.content, m.sent_at, c.name AS group_name FROM social_media.messages m JOIN social_media.conversations c ON m.conversation_id = c.conversation_id WHERE m.sender_user_id = 'U101' AND c.type = 'group';"
},
{
"role": "user",
"content": "Now filter to include only messages sent in June 2024 and order them by sent time descending."
},
{
"role": "assistant",
"content": "SELECT m.content, m.sent_at, c.name AS group_name FROM social_media.messages m JOIN social_media.conversations c ON m.conversation_id = c.conversation_id WHERE m.sender_user_id = 'U101' AND c.type = 'group' AND m.sent_at >= '2024-06-01' AND m.sent_at < '2024-07-01' ORDER BY m.sent_at DESC;"
},
{
"role": "user",
"content": "Also limit the results to the top 15."
},
{
"role": "assistant",
"content": "SELECT m.content, m.sent_at, c.name AS group_name FROM social_media.messages m JOIN social_media.conversations c ON m.conversation_id = c.conversation_id WHERE m.sender_user_id = 'U101' AND c.type = 'group' AND m.sent_at >= '2024-06-01' AND m.sent_at < '2024-07-01' ORDER BY m.sent_at DESC LIMIT 15;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE social_media.messages (
message_id character varying(64) NOT NULL, -- unique identifier for the message
conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
content text, -- textual content of the message
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
read_at timestamp, -- timestamp when message was read by recipient(s)
PRIMARY KEY (message_id)
)
|
[
{
"role": "user",
"content": "List each employee's first and last name along with the count of active services offered by their agency."
},
{
"role": "assistant",
"content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name;"
},
{
"role": "user",
"content": "Actually, only include employees whose service count is greater than 5."
},
{
"role": "assistant",
"content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(s.service_id) > 5;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )
CREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )
CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )
CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )
CREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )
CREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )
CREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )
CREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )
CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )
|
[
{
"role": "user",
"content": "List all patients born in the 1980s, including their full names and genders."
},
{
"role": "assistant",
"content": "SELECT CONCAT(first_name, ' ', last_name) AS full_name, gender FROM healthcare.patients WHERE date_of_birth BETWEEN '1980-01-01' AND '1989-12-31';"
},
{
"role": "user",
"content": "Now filter it to only show female patients who have a phone number listed."
},
{
"role": "assistant",
"content": "SELECT CONCAT(first_name, ' ', last_name) AS full_name, gender FROM healthcare.patients WHERE date_of_birth BETWEEN '1980-01-01' AND '1989-12-31' AND gender = 'Female' AND phone_number IS NOT NULL;"
},
{
"role": "user",
"content": "Can you also include their email addresses in the results?"
},
{
"role": "assistant",
"content": "SELECT CONCAT(first_name, ' ', last_name) AS full_name, gender, email FROM healthcare.patients WHERE date_of_birth BETWEEN '1980-01-01' AND '1989-12-31' AND gender = 'Female' AND phone_number IS NOT NULL;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
|
[
{
"role": "user",
"content": "List all rooms that have a 'Jacuzzi' feature, including the room_number, property_id, type_name, and base_rate."
},
{
"role": "assistant",
"content": "SELECT r.room_number,\n r.property_id,\n rt.type_name,\n rt.base_rate\nFROM hospitality_technology.rooms AS r\nJOIN hospitality_technology.room_types AS rt\n ON r.room_type_id = rt.room_type_id\n AND r.property_id = rt.property_id\nWHERE r.features ILIKE '%Jacuzzi%';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )
CREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )
CREATE TABLE hospitality_technology.staff ( staff_id.text, property_id.text, first_name.text, last_name.text, position.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, is_active.boolean, access_level.integer, manager_id.text, created_at.timestamp )
CREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )
CREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )
CREATE TABLE hospitality_technology.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )
|
[
{
"role": "user",
"content": "Find all wallets created by users in the last 7 days along with any tokens that have a total supply greater than 10 million, showing the wallet address and token details."
},
{
"role": "assistant",
"content": "SELECT w.address AS wallet_address, t.token_name, t.token_symbol, t.total_supply, t.contract_address FROM web3.wallets w JOIN web3.tokens t ON t.total_supply > 10000000 WHERE w.created_at >= CURRENT_DATE - INTERVAL '7 days';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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) )
CREATE 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) )
|
[
{
"role": "user",
"content": "List all NFT collections where the floor price is greater than 0.5 ETH, including their names and contract addresses."
},
{
"role": "assistant",
"content": "SELECT name, contract_address FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH';"
},
{
"role": "user",
"content": "Can you also include the banner image URL and filter to only show ERC721 collections?"
},
{
"role": "assistant",
"content": "SELECT name, contract_address, banner_image_url FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721';"
},
{
"role": "user",
"content": "Now sort these results by floor price in descending order and limit to the top 10."
},
{
"role": "assistant",
"content": "SELECT name, contract_address, banner_image_url, floor_price FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721' ORDER BY CAST(floor_price AS decimal) DESC LIMIT 10;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE token_metas (
block_timestamp timestamp(6) NOT NULL, -- Timestamp of the block when token metadata was recorded
block_number bigint NOT NULL, -- Block number uniquely identifying the block
transaction_hash varchar NOT NULL, -- Hash value of the transaction
transaction_index bigint NOT NULL, -- Index of the transaction within the block
from_address varchar NOT NULL, -- Address from which the transaction originated
contract_address varchar NOT NULL, -- Address of the token contract
symbol varchar NOT NULL, -- Symbol of the token
total_supply varchar NOT NULL, -- erc20 contract total supply
name varchar NOT NULL, -- Name of the token
decimals bigint NOT NULL, -- Number of decimal places for the token
is_erc20 integer NOT NULL, -- Flag indicating if the token is an ERC-20 token (0 or 1)
is_erc721 integer NOT NULL, -- Flag indicating if the token is an ERC-721 token (0 or 1)
is_erc1155 integer NOT NULL, -- Flag indicating if the token is an ERC-1155 token (0 or 1)
is_proxy integer NOT NULL, -- Flag indicating if the token is a proxy (0 or 1)
extra_info varchar NOT NULL, -- Additional information about the token
pk integer NOT NULL -- Partition key for the table(floor(block_number / 5760))
)
CREATE TABLE erc1155_approval_for_all (
block_number bigint NOT NULL, -- Block number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction
transaction_index integer NOT NULL, -- Index of the transaction within the block
transaction_hash varchar(66) NOT NULL, -- Transaction hash
log_index integer NOT NULL, -- Log index
contract_address varchar(42) NOT NULL -- Event contract address
)
CREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )
CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE nft_holders (
block_number bigint NOT NULL, -- Block number containing the transaction
contract_address varchar NOT NULL, -- Event contract address
wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)
token_id varchar NOT NULL, -- NFT token id
contract_type varchar NOT NULL, -- NFT contract type
amount varchar NOT NULL, -- Number of held NFTs
pk varchar NOT NULL -- The last string partition of the contract.
)
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )
CREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )
CREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )
CREATE TABLE 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 )
CREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )
CREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )
CREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )
CREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )
CREATE TABLE token_info (
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
tick varchar NOT NULL, -- Token tick
max_supply decimal(38,0) NOT NULL, -- Max supply
lim decimal(38,0) NOT NULL, -- Limit of each mint
wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint
dec integer NOT NULL, -- Decimal for minimum divie
creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)
)
CREATE TABLE token_activities (
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
log_index integer NOT NULL, -- Index of the log within the transaction
type varchar NOT NULL, -- mint | transfer | burn
tick varchar NOT NULL, -- Token tick
id varchar(255) NOT NULL, -- Unique identifier of the inscription
amt decimal(38,0) NOT NULL, -- Mint amount
from_address varchar(42) NOT NULL, -- Address sending the inscription (matches from_address in transactions table)
to_address varchar(42) NOT NULL -- Address receiving the inscription (match to_address in transactions table)
)
CREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )
|
[
{
"role": "user",
"content": "List all claim IDs that have both an 'Accident Report' and a 'Damage Assessment' document, and show the earliest upload timestamp for each type."
},
{
"role": "assistant",
"content": "SELECT a.claim_id,\n MIN(a.uploaded_at) AS accident_report_date,\n MIN(d.uploaded_at) AS damage_assessment_date\nFROM insurance.claim_documents AS a\nJOIN insurance.claim_documents AS d\n ON a.claim_id = d.claim_id\nWHERE a.document_type = 'Accident Report'\n AND d.document_type = 'Damage Assessment'\nGROUP BY a.claim_id;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )
|
[
{
"role": "user",
"content": "How many unique IP addresses are there in the nodes table?"
},
{
"role": "assistant",
"content": "SELECT COUNT(DISTINCT ip_address) FROM blockchain.nodes;"
},
{
"role": "user",
"content": "Can you break this down by port numbers, showing the count of nodes for each port?"
},
{
"role": "assistant",
"content": "SELECT port, COUNT(node_id) as node_count FROM blockchain.nodes GROUP BY port;"
},
{
"role": "user",
"content": "Now, order these results by node_count in descending order."
},
{
"role": "assistant",
"content": "SELECT port, COUNT(node_id) as node_count FROM blockchain.nodes GROUP BY port ORDER BY node_count DESC;"
},
{
"role": "user",
"content": "Actually, I only want to see ports that have more than 5 nodes."
},
{
"role": "assistant",
"content": "SELECT port, COUNT(node_id) as node_count FROM blockchain.nodes GROUP BY port HAVING COUNT(node_id) > 5 ORDER BY node_count DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE blockchain.nodes ( node_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )
|
[
{
"role": "user",
"content": "List all peers who were last seen after July 10, 2024, along with their IP address and port."
},
{
"role": "assistant",
"content": "SELECT peer_id, ip_address, port, last_seen\nFROM trading_platform.peers\nWHERE last_seen > '2024-07-10'\nORDER BY last_seen DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE trading_platform.users (
user_id character varying(64) NOT NULL, -- unique identifier for the user
username character varying(128) NOT NULL, -- username of the user
email character varying(128) NOT NULL, -- email address of the user
password_hash text NOT NULL, -- hashed password of the user
created_at timestamp NOT NULL, -- time when the user account was created
PRIMARY KEY (user_id)
)
CREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )
CREATE TABLE trading_platform.orders ( order_id.text, user_id.text, wallet_id.text, asset_id.text, order_type.text, quantity.numeric, price.numeric, status.text, created_at.timestamp )
CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )
CREATE TABLE trading_platform.kyc_audit (
kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit
user_id character varying(64) NOT NULL, -- identifier of the user being audited
status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)
reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed
PRIMARY KEY (kyc_audit_id)
)
CREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )
CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.