conversations
listlengths 2
8
| system
stringlengths 288
8.08k
|
|---|---|
[
{
"role": "user",
"content": "Find all contracts where the deployer address is the same as the contract address, indicating self-deployed contracts, and show their network IDs and deployment timestamps."
},
{
"role": "assistant",
"content": "SELECT address, network_id, deployed_at FROM web3.contracts WHERE address = deployer_address;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )
|
[
{
"role": "user",
"content": "How many documents are there for each document_type? Show document_type and count ordered by the count in descending order."
},
{
"role": "assistant",
"content": "SELECT document_type,\n COUNT(*) AS count\nFROM legal_services.documents\nGROUP BY document_type\nORDER BY 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 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": "Find transactions that triggered events and whose to_address matches the contract_id of the emitted event. List the transaction ID, the to_address, and the count of such events for that transaction."
},
{
"role": "assistant",
"content": "SELECT t.transaction_id, t.to_address, COUNT(e.event_id) AS matching_event_count FROM web3.transactions t JOIN web3.events e ON t.transaction_id = e.transaction_id WHERE t.to_address IS NOT NULL AND t.to_address = e.contract_id GROUP BY t.transaction_id, t.to_address;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE web3.events (
event_id character varying(64) NOT NULL, -- unique identifier for the event
contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event
event_name character varying(128) NOT NULL, -- name of the event
data text NOT NULL, -- data payload of the event
emitted_at timestamp NOT NULL, -- time when the event was emitted
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event
log_index integer NOT NULL, -- index of the event log in the transaction
PRIMARY KEY (event_id)
)
CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )
CREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )
|
[
{
"role": "user",
"content": "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 )
|
[
{
"role": "user",
"content": "How many messages in total have been sent that do not contain any media attachment?"
},
{
"role": "assistant",
"content": "SELECT COUNT(*) AS non_media_message_count\nFROM social_media.messages\nWHERE media_url IS NULL OR media_url = '';"
}
] |
You are an SQL statement 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 text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )
|
[
{
"role": "user",
"content": "Compute the total invoiced amount and average payment delay (in days) by status for invoices issued between 2024-01-01 and 2024-06-30."
},
{
"role": "assistant",
"content": "SELECT status,\n SUM(total_amount) AS total_invoiced,\n AVG(EXTRACT(day FROM (payment_date::date - issue_date))) AS avg_payment_delay_days\n FROM legal_services.invoices\n WHERE issue_date BETWEEN '2024-01-01' AND '2024-06-30'\n GROUP BY status;"
},
{
"role": "user",
"content": "Also show the count of invoices per status."
},
{
"role": "assistant",
"content": "SELECT status,\n SUM(total_amount) AS total_invoiced,\n AVG(EXTRACT(day FROM (payment_date::date - issue_date))) AS avg_payment_delay_days,\n COUNT(*) AS invoice_count\n FROM legal_services.invoices\n WHERE issue_date BETWEEN '2024-01-01' AND '2024-06-30'\n GROUP BY status;"
},
{
"role": "user",
"content": "Exclude statuses where total_invoiced is less than 10000."
},
{
"role": "assistant",
"content": "SELECT status,\n SUM(total_amount) AS total_invoiced,\n AVG(EXTRACT(day FROM (payment_date::date - issue_date))) AS avg_payment_delay_days,\n COUNT(*) AS invoice_count\n FROM legal_services.invoices\n WHERE issue_date BETWEEN '2024-01-01' AND '2024-06-30'\n GROUP BY status\nHAVING SUM(total_amount) >= 10000;"
},
{
"role": "user",
"content": "Finally, order the results by avg_payment_delay_days ascending."
},
{
"role": "assistant",
"content": "SELECT status,\n SUM(total_amount) AS total_invoiced,\n AVG(EXTRACT(day FROM (payment_date::date - issue_date))) AS avg_payment_delay_days,\n COUNT(*) AS invoice_count\n FROM legal_services.invoices\n WHERE issue_date BETWEEN '2024-01-01' AND '2024-06-30'\n GROUP BY status\nHAVING SUM(total_amount) >= 10000\n ORDER BY avg_payment_delay_days 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 legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )
|
[
{
"role": "user",
"content": "Show the total transaction amount for each customer, including their full name and risk profile. Join customers to accounts and then to transactions."
},
{
"role": "assistant",
"content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile;"
},
{
"role": "user",
"content": "Filter this report to only include transactions from the last 90 days."
},
{
"role": "assistant",
"content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile;"
},
{
"role": "user",
"content": "Also, only include customers whose total transaction amount in this period exceeds 1000."
},
{
"role": "assistant",
"content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile\nHAVING\n SUM(T1.amount) > 1000;"
},
{
"role": "user",
"content": "Sort the results by total transaction amount in descending order and limit to the top 10 customers."
},
{
"role": "assistant",
"content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile\nHAVING\n SUM(T1.amount) > 1000\nORDER BY\n total_transaction_amount 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 financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )
CREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )
CREATE TABLE financial_services.transactions (
transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction
account_id character varying(64) NOT NULL, -- account involved in the transaction
related_account_id character varying(64), -- counterpart account for transfers
transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest
amount numeric(19, 4) NOT NULL, -- transaction amount
currency character varying(3) NOT NULL, -- transaction currency
transaction_date timestamp NOT NULL, -- exact time of the transaction
effective_date date NOT NULL, -- date the transaction affects the balance
description text, -- description or memo of the transaction
status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed
reference_number character varying(128), -- external reference if applicable (e.g., check number)
PRIMARY KEY (transaction_id),
FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),
FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)
)
CREATE TABLE financial_services.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.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )
CREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )
CREATE TABLE financial_services.employees (
employee_id character varying(64) NOT NULL, -- unique identifier for the employee
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst
department character varying(100), -- e.g., Retail Banking, Wealth Management, IT
branch_id character varying(64), -- Identifier for the branch they work at (if applicable)
email character varying(128) NOT NULL UNIQUE,
phone_extension character varying(20),
hire_date date NOT NULL,
termination_date date, -- Date of termination, null if currently employed
manager_id character varying(64), -- Self-referencing key for manager relationship
status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave
PRIMARY KEY (employee_id),
FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists
FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)
)
|
[
{
"role": "user",
"content": "Find all pairs of transactions that occurred in the same block and were sent to the same address. Show both transaction IDs, the shared recipient address, and the block number."
},
{
"role": "assistant",
"content": "SELECT t1.transaction_id AS tx1,\n t2.transaction_id AS tx2,\n t1.to_address,\n t1.block_number\nFROM transactions t1\nJOIN transactions t2\n ON t1.to_address = t2.to_address\n AND t1.block_number = t2.block_number\n AND t1.transaction_id < t2.transaction_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 web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )
|
[
{
"role": "user",
"content": "For each payment, list its payment_id, guest_id, payment_timestamp, and the next payment_id and next payment_timestamp made by the same guest."
},
{
"role": "assistant",
"content": "SELECT p.payment_id,\n p.guest_id,\n p.payment_timestamp,\n n.payment_id AS next_payment_id,\n n.payment_timestamp AS next_payment_timestamp\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.payments n\n ON p.guest_id = n.guest_id\n AND n.payment_timestamp = (\n SELECT MIN(payment_timestamp)\n FROM hospitality_technology.payments\n WHERE guest_id = p.guest_id\n AND payment_timestamp > p.payment_timestamp\n );"
}
] |
You are an SQL statement 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.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 )
|
[
{
"role": "user",
"content": "List all pairs of wallets that were created within 10 minutes of each other, showing both wallet IDs, the user_id, and both creation timestamps."
},
{
"role": "assistant",
"content": "SELECT\n w1.wallet_id AS wallet1_id,\n w2.wallet_id AS wallet2_id,\n w1.user_id,\n w1.created_at AS created_at1,\n w2.created_at AS created_at2\nFROM web3.wallets w1\nJOIN web3.wallets w2\n ON w1.user_id = w2.user_id\n AND w1.wallet_id < w2.wallet_id\n AND ABS(EXTRACT(EPOCH FROM (w1.created_at - w2.created_at))) <= 600;"
}
] |
You are an SQL statement 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, user_id text, address text, private_key text, created_at timestamp )
|
[
{
"role": "user",
"content": "How many services are defined for each service category?"
},
{
"role": "assistant",
"content": "SELECT category, COUNT(*) AS service_count FROM government_services.services GROUP BY category;"
},
{
"role": "user",
"content": "Only show categories that have more than 15 services listed."
},
{
"role": "assistant",
"content": "SELECT category, COUNT(*) AS service_count FROM government_services.services GROUP BY category HAVING COUNT(*) > 15;"
},
{
"role": "user",
"content": "Could you only count services that are currently marked as active?"
},
{
"role": "assistant",
"content": "SELECT category, COUNT(*) AS service_count FROM government_services.services WHERE is_active = true GROUP BY category HAVING COUNT(*) > 15;"
},
{
"role": "user",
"content": "Also, for these categories, provide the average standard fee for the active services."
},
{
"role": "assistant",
"content": "SELECT category, COUNT(*) AS service_count, AVG(standard_fee) AS average_fee FROM government_services.services WHERE is_active = true GROUP BY category HAVING COUNT(*) > 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 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 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, -- unique identifier for the service
agency_id character varying(64) NOT NULL, -- FK to agencies table
service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)
description text,
category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits
eligibility_criteria text, -- description of who is eligible
standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service
average_processing_time_days integer, -- estimated processing time
is_active boolean DEFAULT true, -- whether the service is currently offered
online_application_url character varying(255),
PRIMARY KEY (service_id)
)
CREATE TABLE government_services.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 PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )
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.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) )
|
[
{
"role": "user",
"content": "Show me the number of guests for each city they reside in."
},
{
"role": "assistant",
"content": "SELECT city, count(*) AS guest_count FROM hospitality_technology.guests WHERE city IS NOT NULL GROUP BY city;"
},
{
"role": "user",
"content": "Now, only show cities with more than 10 guests and order the results by the guest count in descending order."
},
{
"role": "assistant",
"content": "SELECT city, count(*) AS guest_count FROM hospitality_technology.guests WHERE city IS NOT NULL GROUP BY city HAVING count(*) > 10 ORDER BY guest_count DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )
|
[
{
"role": "user",
"content": "What is the total and average amount of unspent UTXOs per address?"
},
{
"role": "assistant",
"content": "SELECT\n address,\n COUNT(*) AS utxo_count,\n SUM(amount) AS total_unspent_amount,\n AVG(amount) AS average_unspent_amount\nFROM trading_platform.utxos\nWHERE spent = FALSE\nGROUP BY address;"
}
] |
You are an SQL statement 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.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )
CREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )
CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
|
[
{
"role": "user",
"content": "能否帮我统计特定车站(station_id 为 'station_xyz')的所有工作人员数量?"
},
{
"role": "assistant",
"content": "MATCH (s:Station {station_id: 'station_xyz'})<-[:BASED_AT]-(staff:Staff)\nRETURN COUNT(staff) AS total_staff"
}
] |
You are an expert in writing database language. You 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: :Station
// Properties:
// station_id: String (Constraint: UNIQUE)
// station_name: String
// city: String (Index recommended)
// state_province: String
// country_code: String
// address: String
// timezone: String
// number_of_platforms: Integer
// created_at: DateTime
// last_updated_at: DateTime
// Example Cypher CREATE:
// CREATE (:Station {station_id: 'station_xyz', station_name: 'Grand Central Terminal', city: 'New York', ...})
// Node Label: :Platform
// Properties:
// platform_id: String (Constraint: UNIQUE)
// platform_number: String
// track_number: String
// status: String
// length_meters: Float
// accessible: Boolean
// Relationship: (:Platform)-[:LOCATED_AT]->(:Station)
// Example Cypher CREATE:
// MATCH (s:Station {station_id: 'station_xyz'})
// CREATE (p:Platform {platform_id: 'plat_123', ...})-[:LOCATED_AT]->(s)
// Node Label: :Train
// Properties:
// train_id: String (Constraint: UNIQUE)
// train_number: String (Constraint: UNIQUE)
// model: String
// manufacturer: String
// year_manufactured: Integer
// capacity: Integer
// status: String
// last_maintenance_date: Date
// next_maintenance_date: Date
// Example Cypher CREATE:
// CREATE (:Train {train_id: 'train_789', train_number: 'Acela 2151', ...})
// Node Label: :TrainCar
// Properties:
// car_id: String (Constraint: UNIQUE)
// car_number: String
// car_type: String
// class: String
// capacity: Integer
// features: String (Or List<String> if driver supports)
// Relationship: (:TrainCar)-[:PART_OF_TRAIN]->(:Train)
// Example Cypher CREATE:
// MATCH (t:Train {train_id: 'train_789'})
// CREATE (c:TrainCar {car_id: 'car_abc', ...})-[:PART_OF_TRAIN]->(t)
// Node Label: :Route
// Properties:
// route_id: String (Constraint: UNIQUE)
// route_name: String
// description: String
// is_active: Boolean
// Relationships:
// (:Route)-[:STARTS_AT]->(:Station)
// (:Route)-[:ENDS_AT]->(:Station)
// Example Cypher CREATE:
// MATCH (origin:Station {station_id: 'station_bos'}), (dest:Station {station_id: 'station_was'})
// CREATE (r:Route {route_id: 'route_ne_corr', ...})-[:STARTS_AT]->(origin), (r)-[:ENDS_AT]->(dest)
// Relationship: (:Route)-[rel:HAS_STOP]->(:Station)
// Relationship Properties on :HAS_STOP:
// sequence_order: Integer
// distance_from_previous_km: Float
// typical_stop_duration_minutes: Integer
// Example Cypher CREATE:
// MATCH (r:Route {route_id: 'route_ne_corr'}), (s:Station {station_id: 'station_pvd'})
// CREATE (r)-[:HAS_STOP {sequence_order: 2, distance_from_previous_km: 70.5, ...}]->(s)
// Node Label: :ScheduledTrip (or just :Trip)
// Properties:
// schedule_id: String (Constraint: UNIQUE)
// departure_datetime: DateTime
// arrival_datetime: DateTime
// status: String
// notes: String
// Relationships:
// (:ScheduledTrip)-[:USES_TRAIN]->(:Train)
// (:ScheduledTrip)-[:FOLLOWS_ROUTE]->(:Route)
// Example Cypher CREATE:
// MATCH (t:Train {train_id: 'train_789'}), (r:Route {route_id: 'route_ne_corr'})
// CREATE (sched:ScheduledTrip {schedule_id: 'sched_1122', ...})-[:USES_TRAIN]->(t), (sched)-[:FOLLOWS_ROUTE]->(r)
// Relationship: (:ScheduledTrip)-[rel:SCHEDULED_STOP]->(:Station)
// Relationship Properties on :SCHEDULED_STOP:
// sequence_order: Integer
// platform_id: String (references Platform node if modeled, or just store ID)
// scheduled_arrival_time: DateTime
// scheduled_departure_time: DateTime
// actual_arrival_time: DateTime
// actual_departure_time: DateTime
// status: String
// Example Cypher CREATE:
// MATCH (sched:ScheduledTrip {schedule_id: 'sched_1122'}), (s:Station {station_id: 'station_pvd'})
// CREATE (sched)-[:SCHEDULED_STOP {sequence_order: 2, platform_id: 'plat_pvd_1', ...}]->(s)
// Node Label: :Passenger
// Properties:
// passenger_id: String (Constraint: UNIQUE)
// first_name: String
// last_name: String
// email: String (Constraint: UNIQUE, if not null)
// phone_number: String (Constraint: UNIQUE, if not null)
// date_of_birth: Date
// loyalty_program_id: String
// created_at: DateTime
// Example Cypher CREATE:
// CREATE (:Passenger {passenger_id: 'pass_pqr', first_name: 'Alice', ...})
// Node Label: :Booking
// Properties:
// booking_id: String (Constraint: UNIQUE)
// booking_datetime: DateTime
// status: String
// total_price: Float
// currency_code: String
// special_requests: String
// Relationships:
// (:Passenger)-[:MADE_BOOKING]->(:Booking)
// (:Booking)-[:FOR_TRIP]->(:ScheduledTrip)
// Example Cypher CREATE:
// MATCH (p:Passenger {passenger_id: 'pass_pqr'}), (sched:ScheduledTrip {schedule_id: 'sched_1122'})
// CREATE (p)-[:MADE_BOOKING]->(b:Booking {booking_id: 'book_zyx', ...})-[:FOR_TRIP]->(sched)
// Node Label: :Ticket
// Properties:
// ticket_id: String (Constraint: UNIQUE)
// seat_number: String
// ticket_type: String
// price: Float
// is_checked_in: Boolean
// qr_code_data: String
// Relationships:
// (:Ticket)-[:PART_OF_BOOKING]->(:Booking)
// (:Ticket)-[:ASSIGNED_TO_CAR]->(:TrainCar)
// Example Cypher CREATE:
// MATCH (b:Booking {booking_id: 'book_zyx'}), (c:TrainCar {car_id: 'car_abc'})
// CREATE (t:Ticket {ticket_id: 'tkt_1a2b', ...})-[:PART_OF_BOOKING]->(b), (t)-[:ASSIGNED_TO_CAR]->(c)
// Node Label: :Staff
// Properties:
// staff_id: String (Constraint: UNIQUE)
// first_name: String
// last_name: String
// role: String
// employee_number: String (Constraint: UNIQUE)
// hire_date: Date
// contact_email: String (Constraint: UNIQUE, if not null)
// contact_phone: String
// is_active: Boolean
// Relationship (Optional):
// (:Staff)-[:BASED_AT]->(:Station)
// Example Cypher CREATE:
// CREATE (:Staff {staff_id: 'staff_mno', first_name: 'Bob', ...})
// OPTIONAL MATCH (s:Station {station_id: 'station_xyz'}) // If primary_station_id exists
// WITH s, staff_mno // Need to get the created staff node reference
// WHERE s IS NOT NULL
// CREATE (staff_mno)-[:BASED_AT]->(s)
|
[
{
"role": "user",
"content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 12 months, along with their token symbol and price from the token_basic_info table."
},
{
"role": "assistant",
"content": "SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) ORDER BY pfr.valuation DESC LIMIT 5;"
},
{
"role": "user",
"content": "Can you also include the 24-hour trading volume for these projects' tokens and filter to only include projects with valuation over $100 million?"
},
{
"role": "assistant",
"content": "SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price, tbi.total_volume FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) AND pfr.valuation > 100000000 ORDER BY pfr.valuation DESC LIMIT 5;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
"CREATE TABLE project_fundraising_record (",
"id character varying(32) NOT NULL, -- fundraising record id",
"project_id character varying(32) NOT NULL, -- the invested project's id",
"project_name character varying(128) NOT NULL, -- name of the invested project",
"rounds_name character varying(32), -- name of the fundraising round",
"investment_value numeric(38,14), -- amount of the fundraising in USD",
"investment_date character varying(128), -- the date of the investment happened",
"introduction character varying(128), -- the introduction of the invested project",
"valuation numeric(38,14), -- the valuation of the project in USD when invested",
CREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )
CREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )
CREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )
CREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )
"CREATE TABLE smart_money_token_performance (",
"token_address character varying(100) NOT NULL, -- the token's address",
"token_symbol character varying(100), -- the tokens's symbol",
"pnl numeric(38,2), -- the profit users made on this token",
"net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token",
"avg_cost numeric(38,16), -- the average cost price of user spent on this token",
"price double precision, -- the current price of the token",
"realized_ratio numeric(10,2), -- the ratio user sold of the token",
"roi numeric(10,2), -- the roi users made of this token",
"chain character varying(100), -- the chain that the token resides",
"PRIMARY KEY (token_address, chain));",
"CREATE TABLE smart_money_token_inflow (",
"token_address character varying(100) NOT NULL, -- the token's address",
"token_symbol character varying(100), -- the tokens's symbol",
"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token",
"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token",
"avg_price numeric(38,6), -- the average cost price of user spent on this token",
"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling",
"address_amount integer, -- the amount of the user bought this token",
"narrative character varying(100), -- the category or narrative of the token",
"chain character varying(100), -- the chain that the token resides",
",PRIMARY KEY (token_address, chain)",
|
[
{
"role": "user",
"content": "Show me the top 5 narratives by market cap, along with their 24-hour trading volume and 7-day price change percentage."
},
{
"role": "assistant",
"content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;"
},
{
"role": "user",
"content": "Can you also include the top 3 coins for each of these narratives?"
},
{
"role": "assistant",
"content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric, top_3_coins.text FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )
|
[
{
"role": "user",
"content": "Show me all properties in California with their star ratings and the total number of rooms they have, ordered by the room count in descending order."
},
{
"role": "assistant",
"content": "SELECT p.property_id, p.property_name, p.star_rating, COUNT(r.room_id) AS room_count FROM hospitality_technology.properties p LEFT JOIN hospitality_technology.rooms r ON p.property_id = r.property_id WHERE p.state_province = 'California' GROUP BY p.property_id, p.property_name, p.star_rating ORDER BY room_count DESC;"
},
{
"role": "user",
"content": "Now, include only properties with a star rating of 4.0 or higher and show the average base rate of their room types."
},
{
"role": "assistant",
"content": "SELECT p.property_id, p.property_name, p.star_rating, COUNT(r.room_id) AS room_count, AVG(rt.base_rate) AS avg_base_rate FROM hospitality_technology.properties p LEFT JOIN hospitality_technology.rooms r ON p.property_id = r.property_id LEFT JOIN hospitality_technology.room_types rt ON p.property_id = rt.property_id WHERE p.state_province = 'California' AND p.star_rating >= 4.0 GROUP BY p.property_id, p.property_name, p.star_rating ORDER BY room_count DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )
CREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )
CREATE TABLE hospitality_technology.reservations (
reservation_id character varying(64) NOT NULL, -- unique identifier for the booking
property_id character varying(64) NOT NULL, -- FK to properties table
guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)
room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)
room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)
check_in_date date NOT NULL, -- scheduled check-in date
check_out_date date NOT NULL, -- scheduled check-out date
actual_check_in_ts timestamp with time zone, -- actual check-in time
actual_check_out_ts timestamp with time zone, -- actual check-out time
num_adults integer NOT NULL, -- number of adults
num_children integer DEFAULT 0, -- number of children
status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow
booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn
rate_plan_id character varying(64), -- FK to rate_plans table (optional)
total_amount numeric(12, 2), -- estimated or final total cost
amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid
special_requests text, -- specific guest requests for this booking
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (reservation_id),
FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),
FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),
FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),
FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)
)
CREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )
CREATE TABLE hospitality_technology.services (
service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service
property_id character varying(64) NOT NULL, -- FK to properties table
service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt
description text,
category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities
price numeric(10, 2) NOT NULL, -- price per unit/instance
unit character varying(30), -- e.g., Per Item, Per Hour, Per Day
is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?
department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)
PRIMARY KEY (service_id),
FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)
)
CREATE TABLE hospitality_technology.payments ( payment_id text PRIMARY KEY, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )
CREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )
|
[
{
"role": "user",
"content": "Show me document_id, application_id, and verification_status for all documents submitted by citizen 'cit123'."
},
{
"role": "assistant",
"content": "SELECT document_id,\n application_id,\n verification_status\nFROM documents\nWHERE citizen_id = 'cit123';"
},
{
"role": "user",
"content": "I got an error: relation 'documents' does not exist."
},
{
"role": "assistant",
"content": "SELECT document_id,\n application_id,\n verification_status\nFROM government_services.documents\nWHERE citizen_id = 'cit123';"
},
{
"role": "user",
"content": "Now, only include documents where verification_status = 'Pending'."
},
{
"role": "assistant",
"content": "SELECT document_id,\n application_id,\n verification_status\nFROM government_services.documents\nWHERE citizen_id = 'cit123'\n AND verification_status = 'Pending';"
},
{
"role": "user",
"content": "Also, limit the results to files uploaded in 2024."
},
{
"role": "assistant",
"content": "SELECT document_id,\n application_id,\n verification_status\nFROM government_services.documents\nWHERE citizen_id = 'cit123'\n AND verification_status = 'Pending'\n AND upload_timestamp >= '2024-01-01'\n AND upload_timestamp < '2025-01-01';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )
CREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )
CREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )
CREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )
CREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )
CREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )
|
[
{
"role": "user",
"content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses."
},
{
"role": "assistant",
"content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.contract_address WHERE tm.is_erc20 = 1 AND tpl.price BETWEEN 1 AND 10;"
},
{
"role": "user",
"content": "I think there's an error in your query - the token_prices_latest table isn't in the schema. Can you modify it to use the token_balances table instead?"
},
{
"role": "assistant",
"content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_balances tb ON tm.contract_address = tb.wallet_address WHERE tm.is_erc20 = 1 AND CAST(tb.amount AS decimal) BETWEEN 1 AND 10;"
},
{
"role": "user",
"content": "That doesn't seem right either. Let's just get the basic ERC20 token information without price filtering for now."
},
{
"role": "assistant",
"content": "SELECT name, symbol, contract_address FROM token_metas WHERE is_erc20 = 1 LIMIT 100;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )
CREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )
CREATE TABLE erc20_balances ( 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, contract_address text, wallet_address text, amount text, pk integer )
CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )
CREATE TABLE 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_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )
CREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )
CREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )
CREATE TABLE token_info (
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
tick varchar NOT NULL, -- Token tick
max_supply decimal(38,0) NOT NULL, -- Max supply
lim decimal(38,0) NOT NULL, -- Limit of each mint
wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint
dec integer NOT NULL, -- Decimal for minimum divie
creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)
)
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash 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 NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )
CREATE TABLE token_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.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 number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction
tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription
wallet_address varchar(42) NOT NULL, -- Address of owner
total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription
amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height
)
CREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )
|
[
{
"role": "user",
"content": "List all tokens with a price below $1 and a 24-hour trading volume over $5 million."
},
{
"role": "assistant",
"content": "SELECT token_name, token_symbol, price, total_volume FROM token_basic_info WHERE price < 1 AND total_volume::numeric > 5000000;"
}
] |
You are an SQL statement 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_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )
|
[
{
"role": "user",
"content": "List every diagnosis description paired with every insurance plan's website."
},
{
"role": "assistant",
"content": "SELECT T1.description, T2.website FROM healthcare.diagnoses AS T1 CROSS JOIN healthcare.insurance_plans AS T2;"
},
{
"role": "user",
"content": "Only include chronic diagnoses and plans whose website ends with '.org'."
},
{
"role": "assistant",
"content": "SELECT T1.description, T2.website FROM healthcare.diagnoses AS T1 CROSS JOIN healthcare.insurance_plans AS T2 WHERE T1.is_chronic = true AND T2.website LIKE '%.org';"
}
] |
You are an SQL statement 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, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )
CREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
|
[
{
"role": "user",
"content": "Can you show me all achievement unlock records where the same player unlocked two different achievements within the same day? Please show player_id, achievement_id_1, achievement_id_2, and the unlock dates for each."
},
{
"role": "assistant",
"content": "SELECT pa1.player_id, pa1.achievement_id as achievement_id_1, pa2.achievement_id as achievement_id_2, pa1.unlocked_at as unlock_date_1, pa2.unlocked_at as unlock_date_2\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.player_id = pa2.player_id\n AND pa1.achievement_id <> pa2.achievement_id\n AND DATE(pa1.unlocked_at) = DATE(pa2.unlocked_at)\n AND pa1.unlocked_at < pa2.unlocked_at;"
},
{
"role": "user",
"content": "Add a condition to only include records where both achievements were unlocked on or after January 1st, 2024."
},
{
"role": "assistant",
"content": "SELECT pa1.player_id, pa1.achievement_id as achievement_id_1, pa2.achievement_id as achievement_id_2, pa1.unlocked_at as unlock_date_1, pa2.unlocked_at as unlock_date_2\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.player_id = pa2.player_id\n AND pa1.achievement_id <> pa2.achievement_id\n AND DATE(pa1.unlocked_at) = DATE(pa2.unlocked_at)\n AND pa1.unlocked_at < pa2.unlocked_at\nWHERE pa1.unlocked_at >= '2024-01-01' AND pa2.unlocked_at >= '2024-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 gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )
|
[
{
"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": "Show me properties that have more than 10 service orders delivered in the last month. Include the property_name and the number of delivered orders."
},
{
"role": "assistant",
"content": "SELECT p.property_name,\n COUNT(o.order_id) AS delivered_orders\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.services s ON p.property_id = s.property_id\nJOIN hospitality_technology.service_orders o ON s.service_id = o.service_id\nWHERE o.status = 'Delivered'\n AND o.delivery_timestamp >= current_date - interval '1 month'\nGROUP BY p.property_name\nHAVING COUNT(o.order_id) > 10;"
},
{
"role": "user",
"content": "Actually, only include those properties where the average total_price per delivered order exceeds 50, and sort by that average descending."
},
{
"role": "assistant",
"content": "SELECT p.property_name,\n COUNT(o.order_id) AS delivered_orders,\n AVG(o.total_price) AS avg_price\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.services s ON p.property_id = s.property_id\nJOIN hospitality_technology.service_orders o ON s.service_id = o.service_id\nWHERE o.status = 'Delivered'\n AND o.delivery_timestamp >= current_date - interval '1 month'\nGROUP BY p.property_name\nHAVING COUNT(o.order_id) > 10\n AND AVG(o.total_price) > 50\nORDER BY avg_price DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.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.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )
CREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )
|
[
{
"role": "user",
"content": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred."
},
{
"role": "assistant",
"content": "SELECT E.event_id, E.event_name, E.transaction_id, T.status, T.value FROM web3.events AS E JOIN web3.transactions AS T ON E.transaction_id = T.transaction_id;"
}
] |
You are an SQL statement 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.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )
CREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )
CREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
|
[
{
"role": "user",
"content": "What is the total number of drivers hired each year? Provide the hire_year and driver_count."
},
{
"role": "assistant",
"content": "SELECT EXTRACT(YEAR FROM hire_date) AS hire_year,\n COUNT(*) AS driver_count\nFROM transportation.drivers\nGROUP BY EXTRACT(YEAR FROM hire_date);"
},
{
"role": "user",
"content": "Now only include years where driver_count > 3 and order the results by driver_count DESC."
},
{
"role": "assistant",
"content": "SELECT hire_year, driver_count\nFROM (\n SELECT EXTRACT(YEAR FROM hire_date) AS hire_year,\n COUNT(*) AS driver_count\n FROM transportation.drivers\n GROUP BY EXTRACT(YEAR FROM hire_date)\n) sub\nWHERE driver_count > 3\nORDER BY driver_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 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 )
|
[
{
"role": "user",
"content": "List developers along with the count of games they released in the 2010s (2010-2019)."
},
{
"role": "assistant",
"content": "SELECT\n d.developer_id,\n d.name,\n COUNT(g.game_id) AS games_in_2010s_count\nFROM\n gaming_technology.developers d\nJOIN\n gaming_technology.games g ON d.developer_id = g.developer_id\nWHERE\n EXTRACT(YEAR FROM g.release_date) BETWEEN 2010 AND 2019\nGROUP BY\n d.developer_id, d.name;"
},
{
"role": "user",
"content": "Only show developers who released more than 3 games in that decade."
},
{
"role": "assistant",
"content": "SELECT\n d.developer_id,\n d.name,\n COUNT(g.game_id) AS games_in_2010s_count\nFROM\n gaming_technology.developers d\nJOIN\n gaming_technology.games g ON d.developer_id = g.developer_id\nWHERE\n EXTRACT(YEAR FROM g.release_date) BETWEEN 2010 AND 2019\nGROUP BY\n d.developer_id, d.name\nHAVING\n COUNT(g.game_id) > 3;"
},
{
"role": "user",
"content": "Can you also include the developer's country in the results?"
},
{
"role": "assistant",
"content": "SELECT\n d.developer_id,\n d.name,\n d.country,\n COUNT(g.game_id) AS games_in_2010s_count\nFROM\n gaming_technology.developers d\nJOIN\n gaming_technology.games g ON d.developer_id = g.developer_id\nWHERE\n EXTRACT(YEAR FROM g.release_date) BETWEEN 2010 AND 2019\nGROUP BY\n d.developer_id, d.name, d.country\nHAVING\n COUNT(g.game_id) > 3;"
}
] |
You are an SQL statement 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 PRIMARY KEY, 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 PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )
CREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )
CREATE TABLE gaming_technology.in_game_items ( item_id uuid PRIMARY KEY, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )
CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )
|
[
{
"role": "user",
"content": "Show the document ID, document type, and upload timestamp for all documents uploaded by citizens who registered after January 1st, 2023."
},
{
"role": "assistant",
"content": "SELECT d.document_id, d.document_type, d.upload_timestamp FROM government_services.documents d JOIN citizens c ON d.citizen_id = c.citizen_id WHERE c.registration_date > '2023-01-01';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE government_services.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 )
|
[
{
"role": "user",
"content": "List all posts where the content mentions 'meeting'."
},
{
"role": "assistant",
"content": "SELECT post_id, user_id, content, created_at FROM social_media.posts WHERE content LIKE '%meeting%'"
},
{
"role": "user",
"content": "Also, only include those posts that are public."
},
{
"role": "assistant",
"content": "SELECT post_id, user_id, content, created_at FROM social_media.posts WHERE content LIKE '%meeting%' AND visibility = 'public'"
}
] |
You are an SQL statement 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.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )
|
[
{
"role": "user",
"content": "Find the contract address and name for all NFT collections listed on the 'Ethereum' blockchain."
},
{
"role": "assistant",
"content": "SELECT contract_address, name FROM nft_collections WHERE blockchain = 'Ethereum'"
},
{
"role": "user",
"content": "For these collections, can you show the count of unique wallet addresses holding NFTs in each collection by joining with nft_holders?"
},
{
"role": "assistant",
"content": "SELECT T1.contract_address, T1.name, COUNT(DISTINCT T2.wallet_address) AS unique_holder_count FROM nft_collections AS T1 JOIN nft_holders AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'Ethereum' GROUP BY T1.contract_address, T1.name"
},
{
"role": "user",
"content": "Please filter the results to only include collections that have more than 100 unique holders."
},
{
"role": "assistant",
"content": "SELECT T1.contract_address, T1.name, COUNT(DISTINCT T2.wallet_address) AS unique_holder_count FROM nft_collections AS T1 JOIN nft_holders AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'Ethereum' GROUP BY T1.contract_address, T1.name HAVING COUNT(DISTINCT T2.wallet_address) > 100"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )
CREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )
CREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )
CREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )
|
[
{
"role": "user",
"content": "Provide a count of notifications, separated by whether they have been read or not."
},
{
"role": "assistant",
"content": "SELECT CASE WHEN T1.read_at IS NULL THEN 'Unread' ELSE 'Read' END, count(T1.notification_id) FROM trading_platform.notifications AS T1 GROUP BY CASE WHEN T1.read_at IS NULL THEN 'Unread' ELSE 'Read' 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 trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )
|
[
{
"role": "user",
"content": "For each asset, calculate the total quantity and average price of orders that have status 'filled'."
},
{
"role": "assistant",
"content": "SELECT o.asset_id,\n SUM(o.quantity) AS total_quantity,\n AVG(o.price) AS average_price\nFROM trading_platform.orders o\nWHERE o.status = 'filled'\nGROUP BY o.asset_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 trading_platform.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 trading_platform.orders (
order_id character varying(64) NOT NULL, -- unique identifier for the order
user_id character varying(64) NOT NULL, -- identifier of the user placing the order
wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order
price numeric(38,14) NOT NULL, -- price per unit of the asset
status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)
created_at timestamp NOT NULL, -- time when the order was created
PRIMARY KEY (order_id)
)
CREATE TABLE trading_platform.assets (
asset_id character varying(64) NOT NULL, -- unique identifier for the asset
name character varying(128) NOT NULL, -- name of the asset
symbol character varying(32) NOT NULL, -- symbol of the asset
type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)
PRIMARY KEY (asset_id)
)
CREATE TABLE trading_platform.utxos (
utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO
output_index integer NOT NULL, -- index of the output in the transaction
address character varying(128) NOT NULL, -- address that can spend the UTXO
amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO
spent boolean NOT NULL, -- whether the UTXO has been spent
PRIMARY KEY (utxo_id)
)
CREATE TABLE trading_platform.dapps (
dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp
name character varying(128) NOT NULL, -- name of the DApp
description text NOT NULL, -- description of the DApp
url character varying(256) NOT NULL, -- URL of the DApp
PRIMARY KEY (dapp_id)
)
CREATE TABLE trading_platform.peers (
peer_id character varying(64) NOT NULL, -- unique identifier for the peer
ip_address character varying(15) NOT NULL, -- IP address of the peer
port integer NOT NULL, -- port number of the peer
last_seen timestamp NOT NULL, -- last time the peer was active
PRIMARY KEY (peer_id)
)
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)
)
CREATE TABLE trading_platform.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
user_id character varying(64) NOT NULL, -- identifier of the user receiving the notification
message text NOT NULL, -- message of the notification
sent_at timestamp NOT NULL, -- time when the notification was sent
read_at timestamp, -- time when the notification was read
PRIMARY KEY (notification_id)
)
|
[
{
"role": "user",
"content": "Which developers have created games that include at least one item of rarity 'Legendary'? Show the developer_id and the item_name."
},
{
"role": "assistant",
"content": "SELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.in_game_items igi ON d.developer_id = igi.game_id /* This assumes developer_id = game_id; adjust join logic as needed */\nWHERE igi.rarity = 'Legendary';"
},
{
"role": "user",
"content": "I think the join is wrong, it should match developers to games and then in_game_items to games. Please revise the SQL."
},
{
"role": "assistant",
"content": "-- Assuming the existence of a 'games' table with columns (game_id, developer_id)\nSELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items igi ON g.game_id = igi.game_id\nWHERE igi.rarity = 'Legendary';"
},
{
"role": "user",
"content": "You can only use the given tables. Is it possible to get a list of developers who have legendary items in their games with the available schema?"
},
{
"role": "assistant",
"content": "-- Based on the given schema alone (without a games table), it's not possible to relate developers to in_game_items directly since there is no relationship between developer_id and game_id in the available tables."
},
{
"role": "user",
"content": "Okay, then just list all 'Legendary' rarity in-game items, including their item_id, item_name, and cost_amount."
},
{
"role": "assistant",
"content": "SELECT item_id, item_name, cost_amount\nFROM gaming_technology.in_game_items\nWHERE rarity = 'Legendary';"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )
CREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )
CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )
CREATE TABLE gaming_technology.in_game_items (
item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition
game_id uuid NOT NULL, -- FK linking to the game this item belongs to
item_name character varying(150) NOT NULL, -- name of the item
item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)
description text, -- description of the item
rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)
cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)
cost_amount numeric(12, 2), -- price if purchasable
attributes jsonb, -- flexible field for item stats or properties
PRIMARY KEY (item_id)
-- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)
)
CREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )
|
[
{
"role": "user",
"content": "List 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": "List all available services in the 'Housekeeping' department that cost less than 20."
},
{
"role": "assistant",
"content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20;"
},
{
"role": "user",
"content": "Sort the results by service_name in ascending order."
},
{
"role": "assistant",
"content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20\nORDER BY service_name ASC;"
}
] |
You are an SQL statement 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.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )
|
[
{
"role": "user",
"content": "Summarize trade activity by account and execution venue, showing the total quantity of shares traded and the average commission paid."
},
{
"role": "assistant",
"content": "SELECT account_id, execution_venue, SUM(quantity) AS total_quantity, AVG(commission) AS average_commission FROM financial_services.trades GROUP BY account_id, execution_venue;"
},
{
"role": "user",
"content": "Refine that report to only include trades where the total_amount for a single trade was greater than 5000. Also, only show account/venue groups where the total quantity traded is at least 100."
},
{
"role": "assistant",
"content": "SELECT account_id, execution_venue, SUM(quantity) AS total_quantity, AVG(commission) AS average_commission FROM financial_services.trades WHERE total_amount > 5000 GROUP BY account_id, execution_venue HAVING SUM(quantity) >= 100;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE financial_services.trades ( trade_id text, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )
|
[
{
"role": "user",
"content": "Which route numbers connect locations with a distance less than 80 km and more than 5 words in their description? Include the route type in the results."
},
{
"role": "assistant",
"content": "SELECT route_number, type FROM transportation.routes WHERE distance_km < 80 AND array_length(regexp_split_to_array(description, '\\s+'), 1) > 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 transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )
|
[
{
"role": "user",
"content": "Show me wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount."
},
{
"role": "assistant",
"content": "SELECT eb.wallet_address, tm.symbol, eb.amount FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address WHERE CAST(eb.amount AS decimal) > 1000;"
},
{
"role": "user",
"content": "Can you join this with the token_prices_latest table to include the current price of each token and sort the results by amount in descending order?"
},
{
"role": "assistant",
"content": "SELECT eb.wallet_address, tm.symbol, eb.amount, tpl.price FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address JOIN token_prices_latest tpl ON eb.contract_address = tpl.address WHERE CAST(eb.amount AS decimal) > 1000 ORDER BY CAST(eb.amount AS decimal) DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )
CREATE TABLE erc1155_approval_for_all (
block_number bigint NOT NULL, -- Block 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, -- Block number containing the transaction
contract_address varchar NOT NULL, -- Event contract address
wallet_address varchar NOT NULL, -- The wallet address for the contract
amount varchar NOT NULL, -- Wallet's on-chain balance at the corresponding block height
pk varchar NOT NULL -- The last string partition of the contract.
)
CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )
CREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )
CREATE TABLE sui_coins_metadata ( object_id 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_collections (
blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract
contract_address varchar NOT NULL, -- Contract address(with bloom filter)
name varchar NOT NULL, -- name fields for the functionType in contract
symbol varchar NOT NULL, -- symbol fields for the functionType in contract
deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract
deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract
erc_type varchar NOT NULL, -- The type of token
owner varchar NOT NULL, -- owner fields for the functionType in contract
traits varchar NOT NULL, -- traits fields for the functionType in contract
description varchar NOT NULL, -- description fields for the functionType in contract
slug varchar NOT NULL, -- slug fields for the functionType in contract
media_info varchar NOT NULL, -- media_info fields for the functionType in contract
image_url varchar NOT NULL, -- image_url fields for the functionType in contract
banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract
updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract
banner varchar NOT NULL, -- banner fields for the functionType in contract
token_count bigint NOT NULL, -- token_count fields for the functionType in contract
floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract
floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract
floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract
pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))
)
CREATE TABLE token_prices (
uuid varchar(36) NOT NULL, -- uuid fields for the functionType in contract
blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract
address varchar(42) NOT NULL, -- address fields for the functionType in contract
decimals bigint NOT NULL, -- decimals fields for the functionType in contract
symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract
price real NOT NULL, -- price fields for the functionType in contract
timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract
)
CREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )
CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_balances_bitcoin (
block_number bigint NOT NULL, -- Block number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction
tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription
wallet_address varchar(42) NOT NULL, -- Address of owner
total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription
amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height
)
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )
CREATE TABLE token_activities_bitcoin (
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
log_index integer NOT NULL, -- Index of the log within the transaction
type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)
tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription
id varchar(255) NOT NULL, -- Unique identifier of the inscription
amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to "lim"
from_address varchar(62) NOT NULL, -- Address sending the inscription
to_address varchar(62) NOT NULL -- Address receiving the inscription
)
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": "I need to find all components associated with a specific supplier. Can you help with that?"
},
{
"role": "assistant",
"content": "HGETALL component:<component_id>\nIF HGET component:<component_id> supplier_id = 'sup:ACME_AERO' THEN INCLUDE"
},
{
"role": "user",
"content": "Can you also show me the material ID for each of these components?"
},
{
"role": "assistant",
"content": "HGETALL component:<component_id>\nIF HGET component:<component_id> supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component:<component_id> material_id"
},
{
"role": "user",
"content": "What if I want to exclude components with a specific material ID?"
},
{
"role": "assistant",
"content": "HGETALL component:<component_id>\nIF HGET component:<component_id> supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component:<component_id> material_id\nIF HGET component:<component_id> material_id != 'mat:TI64' THEN INCLUDE"
},
{
"role": "user",
"content": "Can you add the component name to the result as well?"
},
{
"role": "assistant",
"content": "HGETALL component:<component_id>\nIF HGET component:<component_id> supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component:<component_id> material_id\nIF HGET component:<component_id> material_id != 'mat:TI64' THEN INCLUDE\nHGET component:<component_id> component_name"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
Use Hashes. Key pattern: 'component:<component_id>'. Example: HSET component:LGSTRUT01 part_number "PN-5521-A" component_name "Landing Gear Strut" material_id "mat:TI64" supplier_id "sup:ACME_AERO" ... Consider Sets for reverse lookups (e.g., 'material_components:<material_id>' -> Set<component_id>).
|
[
{
"role": "user",
"content": "Provide a report of each user with their username and the count of all log entries from the last 30 days."
},
{
"role": "assistant",
"content": "SELECT u.user_id, u.username, COUNT(l.log_id) AS log_count\nFROM trading_platform.users u\nLEFT JOIN trading_platform.logs l\n ON u.user_id = l.user_id\n AND l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY u.user_id, u.username;"
},
{
"role": "user",
"content": "Actually, show only logs where the action includes the word 'trade'."
},
{
"role": "assistant",
"content": "SELECT u.user_id, u.username, COUNT(l.log_id) AS log_count\nFROM trading_platform.users u\nJOIN trading_platform.logs l\n ON u.user_id = l.user_id\nWHERE l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\n AND l.action ILIKE '%trade%'\nGROUP BY u.user_id, u.username;"
},
{
"role": "user",
"content": "Also include the earliest log date for each user in that period."
},
{
"role": "assistant",
"content": "SELECT u.user_id,\n u.username,\n COUNT(l.log_id) AS log_count,\n MIN(l.logged_at) AS first_log_date\nFROM trading_platform.users u\nJOIN trading_platform.logs l\n ON u.user_id = l.user_id\nWHERE l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\n AND l.action ILIKE '%trade%'\nGROUP BY u.user_id, u.username;"
},
{
"role": "user",
"content": "Finally, sort the results by log_count descending and limit to the top 5 users."
},
{
"role": "assistant",
"content": "SELECT u.user_id,\n u.username,\n COUNT(l.log_id) AS log_count,\n MIN(l.logged_at) AS first_log_date\nFROM trading_platform.users u\nJOIN trading_platform.logs l\n ON u.user_id = l.user_id\nWHERE l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\n AND l.action ILIKE '%trade%'\nGROUP BY u.user_id, u.username\nORDER BY log_count DESC\nLIMIT 5;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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.orders (
order_id character varying(64) NOT NULL, -- unique identifier for the order
user_id character varying(64) NOT NULL, -- identifier of the user placing the order
wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order
price numeric(38,14) NOT NULL, -- price per unit of the asset
status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)
created_at timestamp NOT NULL, -- time when the order was created
PRIMARY KEY (order_id)
)
CREATE TABLE trading_platform.utxos (
utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO
output_index integer NOT NULL, -- index of the output in the transaction
address character varying(128) NOT NULL, -- address that can spend the UTXO
amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO
spent boolean NOT NULL, -- whether the UTXO has been spent
PRIMARY KEY (utxo_id)
)
CREATE TABLE trading_platform.dapps (
dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp
name character varying(128) NOT NULL, -- name of the DApp
description text NOT NULL, -- description of the DApp
url character varying(256) NOT NULL, -- URL of the DApp
PRIMARY KEY (dapp_id)
)
CREATE TABLE trading_platform.peers (
peer_id character varying(64) NOT NULL, -- unique identifier for the peer
ip_address character varying(15) NOT NULL, -- IP address of the peer
port integer NOT NULL, -- port number of the peer
last_seen timestamp NOT NULL, -- last time the peer was active
PRIMARY KEY (peer_id)
)
CREATE TABLE trading_platform.logs (
log_id character varying(64) NOT NULL, -- unique identifier for the log entry
user_id character varying(64), -- identifier of the user associated with the log entry
action character varying(128) NOT NULL, -- action performed
details text NOT NULL, -- details of the action
logged_at timestamp NOT NULL, -- time when the log entry was created
PRIMARY KEY (log_id)
)
|
[
{
"role": "user",
"content": "Count the number of policies issued in each calendar year, and show the year and the count."
},
{
"role": "assistant",
"content": "SELECT EXTRACT(YEAR FROM issued_at), COUNT(*) FROM insurance.policies WHERE issued_at IS NOT NULL GROUP BY 1 ORDER BY 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 insurance.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )
CREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )
CREATE TABLE insurance.insurance_products ( product_id text, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )
CREATE TABLE insurance.agents ( agent_id text, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )
CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )
|
[
{
"role": "user",
"content": "Retrieve the agency name and the most recent notification sent date for each agency, considering only notifications related to agencies."
},
{
"role": "assistant",
"content": "SELECT a.agency_name, MAX(n.sent_at) AS last_notification_date\nFROM government_services.agencies a\nJOIN government_services.notifications n\n ON n.related_entity_type = 'Agency'\n AND n.related_entity_id = a.agency_id\nGROUP BY a.agency_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 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.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
citizen_id character varying(64) NOT NULL, -- FK to citizens table
application_id character varying(64), -- FK to applications table (optional)
message_subject character varying(255),
message_body text NOT NULL,
channel character varying(30) NOT NULL, -- e.g., Email, SMS, Portal Message, Mail
sent_at timestamp NOT NULL,
status character varying(30) NOT NULL, -- e.g., Queued, Sent, Delivered, Failed, Read
related_entity_type character varying(50), -- e.g., Application, Appointment, Document Request
related_entity_id character varying(64), -- ID of the related entity
PRIMARY KEY (notification_id)
)
|
[
{
"role": "user",
"content": "Show the total number of customers in each state."
},
{
"role": "assistant",
"content": "SELECT\n state,\n COUNT(customer_id)\nFROM insurance.customers\nGROUP BY\n state;"
}
] |
You are an SQL statement 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, 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.claims (
claim_id character varying(64) NOT NULL, -- unique identifier for the claim
policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)
customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)
incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim
reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported
description text NOT NULL, -- detailed description of the incident and claim
estimated_loss numeric(15, 2), -- initial estimated cost of the loss
status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled
settlement_amount numeric(15, 2), -- final amount paid out
settlement_date date,
claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)
police_report_number character varying(100),
PRIMARY KEY (claim_id)
)
CREATE TABLE insurance.insurance_products (
product_id character varying(64) NOT NULL, -- unique identifier for the insurance product
product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')
product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'
description text, -- detailed description of the product
base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments
coverage_details text, -- details about what is covered (could be JSON or structured text)
underwriting_rules text, -- rules used for assessing risk and eligibility
is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp,
PRIMARY KEY (product_id)
)
CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )
|
[
{
"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": "Get each staff member who delivered service orders in the last month and the count of orders they delivered."
},
{
"role": "assistant",
"content": "SELECT s.staff_id,\n s.first_name,\n s.last_name,\n COUNT(so.order_id) AS delivered_orders\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.staff s ON so.staff_id_delivered = s.staff_id\nWHERE so.delivery_timestamp >= date_trunc('month', current_date) - INTERVAL '1 month'\n AND so.delivery_timestamp < date_trunc('month', current_date)\nGROUP BY s.staff_id, s.first_name, s.last_name;"
},
{
"role": "user",
"content": "Actually, only include staff who delivered more than 5 orders and order the result by delivered_orders descending."
},
{
"role": "assistant",
"content": "SELECT s.staff_id,\n s.first_name,\n s.last_name,\n COUNT(so.order_id) AS delivered_orders\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.staff s ON so.staff_id_delivered = s.staff_id\nWHERE so.delivery_timestamp >= date_trunc('month', current_date) - INTERVAL '1 month'\n AND so.delivery_timestamp < date_trunc('month', current_date)\nGROUP BY s.staff_id, s.first_name, s.last_name\nHAVING COUNT(so.order_id) > 5\nORDER BY delivered_orders DESC;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )
CREATE TABLE hospitality_technology.rooms (
room_id character varying(64) NOT NULL, -- unique identifier for the room
property_id character varying(64) NOT NULL, -- FK to properties table
room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')
room_type_id character varying(64) NOT NULL, -- FK to room_types table
floor integer, -- floor number the room is on
status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance
is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag
features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)
current_condition text, -- notes on room condition
last_cleaned_at timestamp with time zone, -- timestamp of last cleaning
PRIMARY KEY (room_id),
FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),
FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)
)
CREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )
CREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )
CREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )
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 )
|
[
{
"role": "user",
"content": "Find services that have associated documents with a 'Pending' verification status. Show the service name and the document type name."
},
{
"role": "assistant",
"content": "SELECT DISTINCT s.service_name, dt.document_type_name FROM government_services.services AS s JOIN government_services.applications AS a ON s.service_id = a.service_id JOIN government_services.application_documents AS ad ON a.application_id = ad.application_id JOIN government_services.document_types AS dt ON ad.document_type_id = dt.document_type_id WHERE ad.verification_status = 'Pending';"
}
] |
You are an SQL statement 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)
)
|
[
{
"role": "user",
"content": "Show me all rooms along with their current overall review rating for each room, including the room number and property id."
},
{
"role": "assistant",
"content": "SELECT r.room_number, r.property_id, AVG(rv.rating_overall) AS average_overall_rating\nFROM hospitality_technology.rooms r\nLEFT JOIN hospitality_technology.reviews rv\n ON r.property_id = rv.property_id\nGROUP BY r.room_number, r.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.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.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )
|
[
{
"role": "user",
"content": "List each driver along with the driver_id of the driver who was hired immediately after them."
},
{
"role": "assistant",
"content": "SELECT d1.driver_id AS current_driver_id, d2.driver_id AS next_driver_id FROM transportation.drivers d1 LEFT JOIN transportation.drivers d2 ON d2.hire_date = (SELECT MIN(hire_date) FROM transportation.drivers WHERE hire_date > d1.hire_date);"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE 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 )
|
[
{
"role": "user",
"content": "How many unread notifications are there with the type 'mention'?"
},
{
"role": "assistant",
"content": "SELECT COUNT(*) FROM social_media.notifications WHERE read_at IS NULL AND notification_type = 'mention';"
}
] |
You are an SQL statement 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.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )
CREATE TABLE social_media.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)
sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)
notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')
target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)
target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created
read_at timestamp, -- timestamp notification was marked as read
PRIMARY KEY (notification_id)
)
|
[
{
"role": "user",
"content": "I need a list of unread notifications for user 'U123', including the sender's username and the notification type."
},
{
"role": "assistant",
"content": "SELECT n.notification_id, u.username AS sender_username, n.notification_type, n.created_at\nFROM social_media.notifications n\nLEFT JOIN social_media.users u ON n.sender_user_id = u.user_id\nWHERE n.recipient_user_id = 'U123'\n AND n.read_at IS NULL;"
},
{
"role": "user",
"content": "Actually, I only want notification_type 'message'."
},
{
"role": "assistant",
"content": "SELECT n.notification_id, u.username AS sender_username, n.notification_type, n.created_at\nFROM social_media.notifications n\nLEFT JOIN social_media.users u ON n.sender_user_id = u.user_id\nWHERE n.recipient_user_id = 'U123'\n AND n.read_at IS NULL\n AND n.notification_type = 'message';"
},
{
"role": "user",
"content": "Please order them by creation time descending."
},
{
"role": "assistant",
"content": "SELECT n.notification_id, u.username AS sender_username, n.notification_type, n.created_at\nFROM social_media.notifications n\nLEFT JOIN social_media.users u ON n.sender_user_id = u.user_id\nWHERE n.recipient_user_id = 'U123'\n AND n.read_at IS NULL\n AND n.notification_type = 'message'\nORDER BY n.created_at DESC;"
},
{
"role": "user",
"content": "Show only the top 20 results."
},
{
"role": "assistant",
"content": "SELECT n.notification_id, u.username AS sender_username, n.notification_type, n.created_at\nFROM social_media.notifications n\nLEFT JOIN social_media.users u ON n.sender_user_id = u.user_id\nWHERE n.recipient_user_id = 'U123'\n AND n.read_at IS NULL\n AND n.notification_type = 'message'\nORDER BY n.created_at 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 social_media.users (
user_id character varying(64) NOT NULL, -- unique identifier for the user
username character varying(50) NOT NULL UNIQUE, -- user's unique handle
email character varying(128) NOT NULL UNIQUE, -- user's email address
password_hash text NOT NULL, -- hashed password
full_name character varying(100), -- user's full name
profile_picture_url text, -- URL to the profile picture
bio text, -- short user biography
location character varying(100), -- user's location
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update
is_verified boolean NOT NULL DEFAULT false, -- verification status
PRIMARY KEY (user_id)
)
CREATE TABLE social_media.post_hashtags (
post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link
post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)
hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)
PRIMARY KEY (post_hashtag_id),
CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post
)
CREATE TABLE social_media.messages (
message_id character varying(64) NOT NULL, -- unique identifier for the message
conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
content text, -- textual content of the message
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
read_at timestamp, -- timestamp when message was read by recipient(s)
PRIMARY KEY (message_id)
)
CREATE TABLE social_media.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)
sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)
notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')
target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)
target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created
read_at timestamp, -- timestamp notification was marked as read
PRIMARY KEY (notification_id)
)
CREATE TABLE social_media.user_settings (
setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry
user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)
theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')
email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications
push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications
private_profile boolean DEFAULT false, -- is the user profile private
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change
PRIMARY KEY (setting_id)
)
|
[
{
"role": "user",
"content": "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": "What is the history of incidents or accidents that occurred on platform 5 at station GHI?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information about the history of incidents or accidents on platform 5 at station GHI. My data is limited to the structural and operational details of the platforms, such as platform ID, station ID, and status. For incident history, you may need to consult a different database or contact the relevant authorities."
}
] |
You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE train_station_management.platforms ( platform_id.text, station_id.text, platform_number.text, track_number.text, status.text, length_meters.numeric, accessible.boolean )
|
[
{
"role": "user",
"content": "Show me all insurance plans that cover more than 10 patients as their primary insurance, along with the provider name and contact information."
},
{
"role": "assistant",
"content": "SELECT ip.plan_name, ip.insurance_provider, ip.contact_phone, ip.website, COUNT(pi.patient_id) AS patient_count FROM healthcare.insurance_plans ip JOIN healthcare.patient_insurance pi ON ip.plan_id = pi.plan_id WHERE pi.is_primary = true GROUP BY ip.plan_id HAVING COUNT(pi.patient_id) > 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 healthcare.patients (
patient_id character varying(64) NOT NULL, -- unique identifier for the patient
first_name character varying(100) NOT NULL, -- patient's first name
last_name character varying(100) NOT NULL, -- patient's last name
date_of_birth date NOT NULL, -- patient's date of birth
gender character varying(10), -- patient's gender (e.g., Male, Female, Other)
address text, -- patient's home address
phone_number character varying(20), -- patient's phone number
email character varying(128) UNIQUE, -- patient's email address
emergency_contact_name character varying(200), -- name of emergency contact
emergency_contact_phone character varying(20), -- phone number of emergency contact
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 (patient_id)
)
CREATE TABLE healthcare.doctors (
doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor
first_name character varying(100) NOT NULL, -- doctor's first name
last_name character varying(100) NOT NULL, -- doctor's last name
specialty character varying(100) NOT NULL, -- doctor's medical specialty
license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number
phone_number character varying(20), -- doctor's contact phone
email character varying(128) UNIQUE, -- doctor's contact email
hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (doctor_id)
)
CREATE TABLE healthcare.appointments (
appointment_id 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.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.medications (
medication_id character varying(64) NOT NULL, -- unique identifier for the medication type
medication_name character varying(255) NOT NULL, -- common or brand name
generic_name character varying(255), -- generic chemical name
manufacturer character varying(100), -- drug manufacturer
ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)
description text, -- description of the medication
PRIMARY KEY (medication_id)
)
CREATE TABLE healthcare.prescriptions (
prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription
record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed
patient_id character varying(64) NOT NULL, -- FK to patients table
doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor
medication_id character varying(64) NOT NULL, -- FK to medications table
dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'
frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'
route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'
start_date date NOT NULL, -- date prescription begins
end_date date, -- date prescription ends (if applicable)
quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)
refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills
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)
)
CREATE TABLE healthcare.patient_insurance (
patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link
patient_id character varying(64) NOT NULL, -- FK to patients table
plan_id character varying(64) NOT NULL, -- FK to insurance_plans table
policy_number character varying(100) NOT NULL, -- patient's policy number
group_number character varying(100), -- group number, if applicable
subscriber_name character varying(200), -- name of the primary policy holder
effective_date date NOT NULL, -- date the coverage begins
expiration_date date, -- date the coverage ends (if known)
is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance
PRIMARY KEY (patient_insurance_id),
UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice
)
|
[
{
"role": "user",
"content": "Show me all invoice numbers and due dates where the amount paid is exactly zero."
},
{
"role": "assistant",
"content": "SELECT invoice_number, due_date FROM legal_services.invoices WHERE amount_paid = 0;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )
|
[
{
"role": "user",
"content": "For each location, what is the average appointment duration? Show location_id and the average duration."
},
{
"role": "assistant",
"content": "SELECT location_id, AVG(duration_minutes) FROM healthcare.appointments GROUP BY location_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 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 )
|
[
{
"role": "user",
"content": "How many smart contracts were created in the year 2023?"
},
{
"role": "assistant",
"content": "SELECT COUNT(*) FROM blockchain.smart_contracts WHERE timestamp >= '2023-01-01' AND timestamp < '2024-01-01';"
},
{
"role": "user",
"content": "List the top 5 creator addresses based on the total number of smart contracts they have deployed."
},
{
"role": "assistant",
"content": "SELECT creator_address, COUNT(*) AS contract_count FROM blockchain.smart_contracts GROUP BY creator_address ORDER BY contract_count DESC LIMIT 5;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE blockchain.smart_contracts ( contract_id.text, creator_address.text, code.text, timestamp.timestamp )
|
[
{
"role": "user",
"content": "List users who have received notifications triggered by another user (non-system notifications). Show the recipient username, notification type, and the sender username."
},
{
"role": "assistant",
"content": "SELECT T1.username AS recipient_username, T2.notification_type, T3.username AS sender_username FROM social_media.users AS T1 JOIN social_media.notifications AS T2 ON T1.user_id = T2.recipient_user_id JOIN social_media.users AS T3 ON T2.sender_user_id = T3.user_id;"
},
{
"role": "user",
"content": "Refine the list from Turn 1 to only include notifications of type 'follow' or 'mention'."
},
{
"role": "assistant",
"content": "SELECT T1.username AS recipient_username, T2.notification_type, T3.username AS sender_username FROM social_media.users AS T1 JOIN social_media.notifications AS T2 ON T1.user_id = T2.recipient_user_id JOIN social_media.users AS T3 ON T2.sender_user_id = T3.user_id WHERE T2.notification_type IN ('follow', 'mention');"
},
{
"role": "user",
"content": "Further filter to only include notifications created in 2024 and order the results by notification creation time descending."
},
{
"role": "assistant",
"content": "SELECT T1.username AS recipient_username, T2.notification_type, T3.username AS sender_username FROM social_media.users AS T1 JOIN social_media.notifications AS T2 ON T1.user_id = T2.recipient_user_id JOIN social_media.users AS T3 ON T2.sender_user_id = T3.user_id WHERE T2.notification_type IN ('follow', 'mention') AND EXTRACT(YEAR FROM T2.created_at) = 2024 ORDER BY T2.created_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 social_media.users (
user_id character varying(64) NOT NULL, -- unique identifier for the user
username character varying(50) NOT NULL UNIQUE, -- user's unique handle
email character varying(128) NOT NULL UNIQUE, -- user's email address
password_hash text NOT NULL, -- hashed password
full_name character varying(100), -- user's full name
profile_picture_url text, -- URL to the profile picture
bio text, -- short user biography
location character varying(100), -- user's location
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update
is_verified boolean NOT NULL DEFAULT false, -- verification status
PRIMARY KEY (user_id)
)
CREATE TABLE social_media.posts (
post_id character varying(64) NOT NULL, -- unique identifier for the post
user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)
content text, -- textual content of the post
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit
visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')
location_lat numeric(9,6), -- latitude of post location
location_lon numeric(9,6), -- longitude of post location
PRIMARY KEY (post_id)
)
CREATE TABLE social_media.comments (
comment_id character varying(64) NOT NULL, -- unique identifier for the comment
post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)
user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)
parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)
content text NOT NULL, -- textual content of the comment
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit
PRIMARY KEY (comment_id)
)
CREATE TABLE social_media.likes (
like_id character varying(64) NOT NULL, -- unique identifier for the like
user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)
post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)
comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred
PRIMARY KEY (like_id),
CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes
CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something
)
CREATE TABLE social_media.follows (
follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship
follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)
following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started
PRIMARY KEY (follow_id),
CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows
)
CREATE TABLE social_media.hashtags (
hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag
tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used
PRIMARY KEY (hashtag_id)
)
CREATE TABLE social_media.messages (
message_id character varying(64) NOT NULL, -- unique identifier for the message
conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
content text, -- textual content of the message
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
read_at timestamp, -- timestamp when message was read by recipient(s)
PRIMARY KEY (message_id)
)
CREATE TABLE social_media.conversations (
conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated
last_message_at timestamp, -- timestamp of the last message in the conversation
is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message
group_name character varying(100), -- name of the group chat (if applicable)
PRIMARY KEY (conversation_id)
)
CREATE TABLE social_media.conversation_participants (
participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry
conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)
user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)
joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation
last_read_at timestamp, -- timestamp indicating up to when the user has read messages
PRIMARY KEY (participant_id),
CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times
)
CREATE TABLE social_media.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)
sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)
notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')
target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)
target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created
read_at timestamp, -- timestamp notification was marked as read
PRIMARY KEY (notification_id)
)
CREATE TABLE social_media.user_settings (
setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry
user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)
theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')
email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications
push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications
private_profile boolean DEFAULT false, -- is the user profile private
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change
PRIMARY KEY (setting_id)
)
|
[
{
"role": "user",
"content": "Show pairs of time entries for the same lawyer on the same date with different billing rates, including both entry IDs, the lawyer ID, the work date, and both billing rates."
},
{
"role": "assistant",
"content": "SELECT a.entry_id AS entry1_id, b.entry_id AS entry2_id, a.lawyer_id, a.date_worked, a.billing_rate AS rate1, b.billing_rate AS rate2\nFROM legal_services.time_entries a\nJOIN legal_services.time_entries b\n ON a.lawyer_id = b.lawyer_id\n AND a.date_worked = b.date_worked\n AND a.entry_id < b.entry_id\n AND a.billing_rate <> b.billing_rate;"
},
{
"role": "user",
"content": "Actually, I only want to include entries where both are billable."
},
{
"role": "assistant",
"content": "SELECT a.entry_id AS entry1_id, b.entry_id AS entry2_id, a.lawyer_id, a.date_worked, a.billing_rate AS rate1, b.billing_rate AS rate2\nFROM legal_services.time_entries a\nJOIN legal_services.time_entries b\n ON a.lawyer_id = b.lawyer_id\n AND a.date_worked = b.date_worked\n AND a.entry_id < b.entry_id\n AND a.billing_rate <> b.billing_rate\nWHERE a.is_billable = true\n AND b.is_billable = true;"
},
{
"role": "user",
"content": "Also, sort the results by lawyer_id, then by date_worked, and then by the absolute difference in billing rates descending."
},
{
"role": "assistant",
"content": "SELECT a.entry_id AS entry1_id, b.entry_id AS entry2_id, a.lawyer_id, a.date_worked, a.billing_rate AS rate1, b.billing_rate AS rate2\nFROM legal_services.time_entries a\nJOIN legal_services.time_entries b\n ON a.lawyer_id = b.lawyer_id\n AND a.date_worked = b.date_worked\n AND a.entry_id < b.entry_id\n AND a.billing_rate <> b.billing_rate\nWHERE a.is_billable = true\n AND b.is_billable = true\nORDER BY a.lawyer_id, a.date_worked, ABS(a.billing_rate - b.billing_rate) 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.time_entries ( entry_id.text, case_id.text, lawyer_id.text, date_worked.date, hours_spent.numeric, billing_rate.numeric, description.text, is_billable.boolean, is_billed.boolean, invoice_id.text, created_at.timestamp )
|
[
{
"role": "user",
"content": "List all patients who have insurance plans with group numbers, showing their patient IDs and the count of such plans per patient."
},
{
"role": "assistant",
"content": "SELECT patient_id, COUNT(*) AS plan_count FROM healthcare.patient_insurance WHERE group_number IS NOT NULL GROUP BY patient_id;"
},
{
"role": "user",
"content": "Actually, I only need patients who have more than 2 such plans."
},
{
"role": "assistant",
"content": "SELECT patient_id, COUNT(*) AS plan_count FROM healthcare.patient_insurance WHERE group_number IS NOT NULL GROUP BY patient_id HAVING COUNT(*) > 2;"
},
{
"role": "user",
"content": "Can you also include the earliest effective date among these plans for each patient?"
},
{
"role": "assistant",
"content": "SELECT patient_id, COUNT(*) AS plan_count, MIN(effective_date) AS earliest_effective_date FROM healthcare.patient_insurance WHERE group_number IS NOT NULL GROUP BY patient_id HAVING COUNT(*) > 2;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE healthcare.patient_insurance (
patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link
patient_id character varying(64) NOT NULL, -- FK to patients table
plan_id character varying(64) NOT NULL, -- FK to insurance_plans table
policy_number character varying(100) NOT NULL, -- patient's policy number
group_number character varying(100), -- group number, if applicable
subscriber_name character varying(200), -- name of the primary policy holder
effective_date date NOT NULL, -- date the coverage begins
expiration_date date, -- date the coverage ends (if known)
is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance
PRIMARY KEY (patient_insurance_id),
UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice
)
|
[
{
"role": "user",
"content": "Count the number of contracts per network and status."
},
{
"role": "assistant",
"content": "SELECT\n network_id,\n status,\n COUNT(*) AS contract_count\nFROM web3.contracts\nGROUP BY network_id, status;"
},
{
"role": "user",
"content": "Actually, please only include statuses with more than 10 contracts."
},
{
"role": "assistant",
"content": "SELECT\n network_id,\n status,\n COUNT(*) AS contract_count\nFROM web3.contracts\nGROUP BY network_id, status\nHAVING COUNT(*) > 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 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)
)
|
[
{
"role": "user",
"content": "List all premium payments that were made using 'credit card' as the payment method."
},
{
"role": "assistant",
"content": "SELECT payment_id, policy_id, customer_id, payment_date, amount_paid, payment_method\nFROM insurance.premium_payments\nWHERE payment_method = 'credit card';"
}
] |
You are an SQL statement 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.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.premium_payments ( payment_id text, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )
|
[
{
"role": "user",
"content": "Get the number of direct reports for each manager, showing manager_id and report_count."
},
{
"role": "assistant",
"content": "SELECT manager_id,\n COUNT(*) AS report_count\nFROM hospitality_technology.staff\nWHERE manager_id IS NOT NULL\nGROUP BY manager_id;"
},
{
"role": "user",
"content": "Exclude managers who have fewer than 2 direct reports."
},
{
"role": "assistant",
"content": "SELECT manager_id,\n COUNT(*) AS report_count\nFROM hospitality_technology.staff\nWHERE manager_id IS NOT NULL\nGROUP BY manager_id\nHAVING COUNT(*) >= 2;"
},
{
"role": "user",
"content": "Also include the manager's full name alongside their ID."
},
{
"role": "assistant",
"content": "SELECT m.staff_id AS manager_id,\n m.first_name || ' ' || m.last_name AS manager_full_name,\n COUNT(s.staff_id) AS report_count\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.staff m\n ON s.manager_id = m.staff_id\nGROUP BY m.staff_id, m.first_name, m.last_name\nHAVING COUNT(s.staff_id) >= 2;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )
|
[
{
"role": "user",
"content": "Show the symbol, name, and total supply for all SUI coins with status 'active'."
},
{
"role": "assistant",
"content": "SELECT scm.symbol, scm.name, scm.coin_type, scm.total_supply\nFROM sui_coins_metadata scm\nWHERE scm.status = 'active';"
},
{
"role": "user",
"content": "I received an error that column 'total_supply' doesn't exist in sui_coins_metadata."
},
{
"role": "assistant",
"content": "SELECT scm.symbol, scm.name, scm.coin_type\nFROM sui_coins_metadata scm\nWHERE scm.status = 'active';"
},
{
"role": "user",
"content": "Now, join with sui_coins to add up the total balance across all owners for each coin_type."
},
{
"role": "assistant",
"content": "SELECT scm.symbol, scm.name, scm.coin_type, SUM(CAST(sc.balance AS NUMERIC)) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'active'\nGROUP BY scm.symbol, scm.name, scm.coin_type;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )
CREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )
CREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )
CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )
CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )
CREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )
CREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )
CREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )
CREATE TABLE 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 text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )
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, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )
|
[
{
"role": "user",
"content": "Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens where the price is greater than $0.10."
},
{
"role": "assistant",
"content": "SELECT tm.name, tm.contract_address, tm.total_supply FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"
},
{
"role": "user",
"content": "Can you also include the symbol and decimals for these tokens?"
},
{
"role": "assistant",
"content": "SELECT tm.name, tm.symbol, tm.contract_address, tm.total_supply, tm.decimals FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"
},
{
"role": "user",
"content": "Now filter these results to only show tokens with decimals equal to 18."
},
{
"role": "assistant",
"content": "SELECT tm.name, tm.symbol, tm.contract_address, tm.total_supply, tm.decimals FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 AND tm.decimals = 18 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )
CREATE TABLE erc20_balances ( 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, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )
CREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )
CREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )
CREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )
CREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )
CREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )
CREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )
CREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )
|
[
{
"role": "user",
"content": "List all claims, including the claim ID, incident date, estimated loss, and the name of the insurance product associated with the policy under which the claim was made."
},
{
"role": "assistant",
"content": "SELECT\n c.claim_id,\n c.incident_date,\n c.estimated_loss,\n ip.product_name\nFROM insurance.claims AS c\nJOIN insurance.policies AS p\n ON c.policy_id = p.policy_id\nJOIN insurance.insurance_products AS ip\n ON p.product_id = ip.product_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.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )
CREATE TABLE insurance.claims (
claim_id character varying(64) NOT NULL, -- unique identifier for the claim
policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)
customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)
incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim
reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported
description text NOT NULL, -- detailed description of the incident and claim
estimated_loss numeric(15, 2), -- initial estimated cost of the loss
status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled
settlement_amount numeric(15, 2), -- final amount paid out
settlement_date date,
claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)
police_report_number character varying(100),
PRIMARY KEY (claim_id)
)
CREATE TABLE insurance.insurance_products (
product_id character varying(64) NOT NULL, -- unique identifier for the insurance product
product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')
product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'
description text, -- detailed description of the product
base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments
coverage_details text, -- details about what is covered (could be JSON or structured text)
underwriting_rules text, -- rules used for assessing risk and eligibility
is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp,
PRIMARY KEY (product_id)
)
CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )
|
[
{
"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 the content of all comments that have received at least one like."
},
{
"role": "assistant",
"content": "SELECT DISTINCT T1.content FROM social_media.comments AS T1 JOIN social_media.likes AS T2 ON T1.comment_id = T2.comment_id;"
},
{
"role": "user",
"content": "Also include the creation time of these comments and the user_id of the commenter?"
},
{
"role": "assistant",
"content": "SELECT DISTINCT T1.comment_id, T1.content, T1.created_at, T1.user_id FROM social_media.comments AS T1 JOIN social_media.likes AS T2 ON T1.comment_id = T2.comment_id;"
},
{
"role": "user",
"content": "Only show comments created before '2024-05-01'."
},
{
"role": "assistant",
"content": "SELECT DISTINCT T1.comment_id, T1.content, T1.created_at, T1.user_id FROM social_media.comments AS T1 JOIN social_media.likes AS T2 ON T1.comment_id = T2.comment_id WHERE T1.created_at < '2024-05-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 character varying(64) NOT NULL, -- unique identifier for the comment
post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)
user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)
parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)
content text NOT NULL, -- textual content of the comment
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit
PRIMARY KEY (comment_id)
)
CREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )
CREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )
|
[
{
"role": "user",
"content": "Show me the top 5 buyers by total trade volume (quantity * price) in the last 30 days, along with their trade count."
},
{
"role": "assistant",
"content": "SELECT buyer_id, COUNT(trade_id) AS trade_count, SUM(quantity * price) AS total_volume FROM trading_platform.trades WHERE traded_at >= NOW() - INTERVAL '30 days' GROUP BY buyer_id ORDER BY total_volume DESC LIMIT 5"
},
{
"role": "user",
"content": "Now modify the query to also include the average trade price for each buyer."
},
{
"role": "assistant",
"content": "SELECT buyer_id, COUNT(trade_id) AS trade_count, SUM(quantity * price) AS total_volume, AVG(price) AS avg_price FROM trading_platform.trades WHERE traded_at >= NOW() - INTERVAL '30 days' GROUP BY buyer_id ORDER BY total_volume DESC LIMIT 5"
},
{
"role": "user",
"content": "Actually, I want to see the results for sellers instead of buyers, and include the distinct asset count they traded."
},
{
"role": "assistant",
"content": "SELECT seller_id, COUNT(trade_id) AS trade_count, COUNT(DISTINCT asset_id) AS distinct_assets, SUM(quantity * price) AS total_volume, AVG(price) AS avg_price FROM trading_platform.trades WHERE traded_at >= NOW() - INTERVAL '30 days' GROUP BY seller_id ORDER BY total_volume DESC LIMIT 5"
}
] |
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.
##Table Structure
CREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )
|
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- -