system
stringlengths 323
8.11k
| conversations
listlengths 2
8
|
|---|---|
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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": "Count the number of posts that have a media URL but no textual content."
},
{
"role": "assistant",
"content": "SELECT COUNT(*) FROM social_media.posts AS T1 WHERE T1.media_url IS NOT NULL AND (T1.content IS NULL OR T1.content = '');"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )
CREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )
CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )
CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )
CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )
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.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": "Retrieve each employee's first and last name along with the count of applications they've been assigned that are currently in the 'Under Review' status."
},
{
"role": "assistant",
"content": "SELECT e.first_name,\n e.last_name,\n COUNT(app.application_id) AS under_review_count\nFROM government_services.employees e\nLEFT JOIN government_services.applications app ON e.employee_id = app.assigned_employee_id\n AND app.status = 'Under Review'\nGROUP BY e.employee_id, e.first_name, e.last_name;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )
CREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )
CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )
CREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )
CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )
CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )
|
[
{
"role": "user",
"content": "List each wallet with its wallet_id, user_id, and the total amount of unspent UTXOs associated with that wallet."
},
{
"role": "assistant",
"content": "SELECT\n w.wallet_id,\n w.user_id,\n COALESCE(SUM(u.amount), 0) AS unspent_total\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.utxos u\n ON w.address = u.address\n AND u.spent = false\nGROUP BY w.wallet_id, w.user_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )
CREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )
CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.trades (
trade_id character varying(64) NOT NULL, -- unique identifier for the trade
order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade
buyer_id character varying(64) NOT NULL, -- identifier of the buyer
seller_id character varying(64) NOT NULL, -- identifier of the seller
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade
price numeric(38,14) NOT NULL, -- price per unit of the asset
traded_at timestamp NOT NULL, -- time when the trade was executed
PRIMARY KEY (trade_id)
)
CREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )
CREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )
CREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )
CREATE TABLE trading_platform.metadata (
metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata
asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
key character varying(128) NOT NULL, -- key of the metadata
value text NOT NULL, -- value of the metadata
PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.kyc_audit (
kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit
user_id character varying(64) NOT NULL, -- identifier of the user being audited
status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)
reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed
PRIMARY KEY (kyc_audit_id)
)
|
[
{
"role": "user",
"content": "Show me a list of all users who have participated in any trade (either as a buyer or a seller), including their username and the total number of trades they were involved in."
},
{
"role": "assistant",
"content": "SELECT T1.username , count(T2.trade_id) FROM trading_platform.users AS T1 JOIN (SELECT buyer_id, trade_id FROM trading_platform.trades UNION ALL SELECT seller_id, trade_id FROM trading_platform.trades) AS T2 ON T1.user_id = T2.buyer_id GROUP BY T1.username"
},
{
"role": "user",
"content": "From that list, now only show users who were involved in at least one trade *as a buyer*, and include their email address as well."
},
{
"role": "assistant",
"content": "SELECT T1.username , T1.email , count(T2.trade_id) FROM trading_platform.users AS T1 JOIN trading_platform.trades AS T2 ON T1.user_id = T2.buyer_id GROUP BY T1.username , T1.email HAVING count(T2.trade_id) >= 1"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.tokens (
token_id character varying(64) NOT NULL, -- unique identifier for the token
contract_address character varying(128) NOT NULL, -- address of the token contract
token_name character varying(128) NOT NULL, -- name of the token
token_symbol character varying(32) NOT NULL, -- symbol of the token
decimals integer NOT NULL, -- number of decimals for the token
total_supply numeric(38,14) NOT NULL, -- total supply of the token
PRIMARY KEY (token_id)
)
|
[
{
"role": "user",
"content": "For each token, show its token_id, decimals, and the average total_supply of all tokens with the same decimals."
},
{
"role": "assistant",
"content": "SELECT t.token_id,\n t.decimals,\n avg_data.avg_total_supply\nFROM web3.tokens t\nJOIN (\n SELECT decimals,\n AVG(total_supply) AS avg_total_supply\n FROM web3.tokens\n GROUP BY decimals\n) AS avg_data\n ON t.decimals = avg_data.decimals;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE token_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 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )
|
[
{
"role": "user",
"content": "How many notifications are there for each status?"
},
{
"role": "assistant",
"content": "SELECT\n status,\n COUNT(*) AS notification_count\nFROM government_services.notifications\nGROUP BY status;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.platforms ( platform_id text, station_id text, platform_number text, track_number text, status text, length_meters numeric, accessible boolean )
|
[
{
"role": "user",
"content": "What is the maintenance schedule for platform 3 at station DEF for the next month?"
},
{
"role": "assistant",
"content": "I'm sorry, but I don't have access to the maintenance schedule for platforms. The data I have only includes static information about platform details such as ID, station, number, track, status, length, and accessibility. For maintenance schedules, you may need to consult the station management or relevant department."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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": "For each chain, which token had the highest number of smart money addresses buying it this week? Show the token symbol and narrative too."
},
{
"role": "assistant",
"content": "SELECT chain, token_symbol, narrative, MAX(address_amount) AS max_buyers FROM smart_money_token_inflow WHERE type = 1 AND DATE_TRUNC('week', CURRENT_DATE) = DATE_TRUNC('week', CURRENT_DATE) GROUP BY chain, token_symbol, narrative;"
},
{
"role": "user",
"content": "I got an error, I think the filter for the week may be wrong. Please revise the query so that it only counts buys from the current week."
},
{
"role": "assistant",
"content": "SELECT chain, token_symbol, narrative, address_amount AS buyers FROM smart_money_token_inflow WHERE type = 1 AND EXTRACT(week FROM CURRENT_DATE) = EXTRACT(week FROM CURRENT_DATE) AND EXTRACT(year FROM CURRENT_DATE) = EXTRACT(year FROM CURRENT_DATE) ORDER BY chain, buyers DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )
|
[
{
"role": "user",
"content": "List all auto loans (loan_id, principal_amount, interest_rate) where the current principal balance is less than 40% of the original principal amount, along with the account_id and the difference between principal_amount and current_principal_balance."
},
{
"role": "assistant",
"content": "SELECT loan_id, principal_amount, interest_rate, account_id, (principal_amount - current_principal_balance) AS amount_paid FROM financial_services.loans WHERE loan_type = 'Auto' AND current_principal_balance < (0.4 * principal_amount);"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users (
user_id character varying(64) NOT NULL, -- 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 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.trades (
trade_id character varying(64) NOT NULL, -- unique identifier for the trade
order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade
buyer_id character varying(64) NOT NULL, -- identifier of the buyer
seller_id character varying(64) NOT NULL, -- identifier of the seller
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade
price numeric(38,14) NOT NULL, -- price per unit of the asset
traded_at timestamp NOT NULL, -- time when the trade was executed
PRIMARY KEY (trade_id)
)
CREATE TABLE trading_platform.assets (
asset_id character varying(64) NOT NULL, -- 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.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": "Show all wallet addresses that have ever received a UTXO."
},
{
"role": "assistant",
"content": "SELECT DISTINCT address\nFROM trading_platform.utxos;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL DEFAULT 'USA', phone_number character varying(30), email character varying(128) UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, status character varying(20) NOT NULL DEFAULT 'Active', PRIMARY KEY (customer_id) )
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.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )
CREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )
CREATE TABLE insurance.premium_payments ( payment_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, amount_paid numeric(12, 2) NOT NULL, payment_method character varying(50), transaction_reference character varying(128) UNIQUE, due_date date, payment_period_start date, payment_period_end date, status character varying(30) NOT NULL DEFAULT 'Completed', PRIMARY KEY (payment_id) )
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) )
CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )
|
[
{
"role": "user",
"content": "What is the average commission rate for all active agents?"
},
{
"role": "assistant",
"content": "SELECT AVG(commission_rate) FROM agents WHERE status = 'Active';"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.staff (
staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew
primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff)
employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier
hire_date date NOT NULL,
contact_email character varying(128) UNIQUE,
contact_phone character varying(32),
is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed?
PRIMARY KEY (staff_id),
FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id)
)
|
[
{
"role": "user",
"content": "What are the specific job responsibilities and daily tasks for a staff member with the role of Station Master?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information about the specific job responsibilities or daily tasks for a Station Master. The data in the staff table only includes basic identification and contact details, role titles, and employment status, without details on job descriptions or duties."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.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 )
|
[
{
"role": "user",
"content": "For each service location, find its nearest accessible location by geographic distance."
},
{
"role": "assistant",
"content": "SELECT sl.location_id,\n sl.location_name,\n nearest.location_id AS nearest_location_id,\n nearest.location_name AS nearest_location_name\nFROM government_services.service_locations sl\nJOIN LATERAL (\n SELECT sl2.location_id,\n sl2.location_name\n FROM government_services.service_locations sl2\n WHERE sl2.is_accessible = TRUE\n AND sl2.location_id <> sl.location_id\n ORDER BY ((sl.latitude - sl2.latitude)^2 + (sl.longitude - sl2.longitude)^2) ASC\n LIMIT 1\n) AS nearest ON TRUE;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )
CREATE TABLE government_services.documents (
document_id character varying(64) NOT NULL, -- unique identifier for the document instance
application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)
citizen_id character varying(64) NOT NULL, -- FK to citizens table
document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate
file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)
upload_timestamp timestamp NOT NULL,
expiry_date date,
verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected
verified_by_employee_id character varying(64), -- FK to employees table
verification_timestamp timestamp,
PRIMARY KEY (document_id)
)
CREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )
CREATE TABLE government_services.employees (
employee_id character varying(64) NOT NULL, -- unique identifier for the government employee
agency_id character varying(64) NOT NULL, -- FK to agencies table
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
job_title character varying(150) NOT NULL,
department character varying(100),
work_email character varying(128) NOT NULL UNIQUE,
work_phone character varying(32),
hire_date date NOT NULL,
termination_date date, -- null if currently employed
access_level character varying(50), -- Role or permission level
manager_employee_id character varying(64), -- FK to self for reporting structure
PRIMARY KEY (employee_id)
)
CREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )
CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )
|
[
{
"role": "user",
"content": "What is the average number of appointments assigned per employee for each job title?"
},
{
"role": "assistant",
"content": "SELECT e.job_title, CAST(COUNT(a.appointment_id) AS REAL) / COUNT(DISTINCT e.employee_id) AS average_appointments_per_employee FROM government_services.employees e LEFT JOIN government_services.appointments a ON e.employee_id = a.employee_id GROUP BY e.job_title;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )
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.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )
|
[
{
"role": "user",
"content": "For each claim, show the corresponding product_type of the insurance product for the related policy."
},
{
"role": "assistant",
"content": "SELECT cl.claim_id, ip.product_type\nFROM insurance.claims cl\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id;"
},
{
"role": "user",
"content": "Sorry, there is no policies table, I got an error. Can you try joining claims to insurance_products another way?"
},
{
"role": "assistant",
"content": "-- Unable to join directly since there is no 'policies' table connecting claims to insurance_products. If policy_id equals product_id, you may try:\nSELECT claim_id, policy_id, product_type\nFROM insurance.claims\nJOIN insurance.insurance_products ON claims.policy_id = insurance_products.product_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.players ( player_id.uuid, 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.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )
CREATE TABLE gaming_technology.game_sessions ( session_id.uuid, player_id.uuid, game_id.uuid, server_id.uuid, start_time.timestamptz, end_time.timestamptz, duration_seconds.integer, score.integer, session_data.jsonb )
CREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )
|
[
{
"role": "user",
"content": "For each achievement, show its name, the game_id it belongs to, and the number of distinct players who have played a session for that game."
},
{
"role": "assistant",
"content": "SELECT a.name, a.game_id, COUNT(DISTINCT gs.player_id) AS players_with_sessions\nFROM gaming_technology.achievements a\nLEFT JOIN gaming_technology.game_sessions gs ON a.game_id = gs.game_id\nGROUP BY a.achievement_id, a.name, a.game_id;"
},
{
"role": "user",
"content": "Now, filter to only include achievements for games that have at least 50 players who have played a session."
},
{
"role": "assistant",
"content": "SELECT a.name, a.game_id, COUNT(DISTINCT gs.player_id) AS players_with_sessions\nFROM gaming_technology.achievements a\nLEFT JOIN gaming_technology.game_sessions gs ON a.game_id = gs.game_id\nGROUP BY a.achievement_id, a.name, a.game_id\nHAVING COUNT(DISTINCT gs.player_id) >= 50;"
},
{
"role": "user",
"content": "Please also include the number of times each achievement has been unlocked by unique players, labeled as unique_unlocks."
},
{
"role": "assistant",
"content": "SELECT a.name, a.game_id, COUNT(DISTINCT gs.player_id) AS players_with_sessions,\n (SELECT COUNT(DISTINCT gs2.player_id)\n FROM gaming_technology.game_sessions gs2\n WHERE gs2.game_id = a.game_id) AS unique_unlocks\nFROM gaming_technology.achievements a\nLEFT JOIN gaming_technology.game_sessions gs ON a.game_id = gs.game_id\nGROUP BY a.achievement_id, a.name, a.game_id\nHAVING COUNT(DISTINCT gs.player_id) >= 50;"
},
{
"role": "user",
"content": "I think unique_unlocks should be the count of distinct players who have unlocked each specific achievement, not just played a session. Can you correct that?"
},
{
"role": "assistant",
"content": "-- With the provided tables, there is no direct record of players unlocking a specific achievement, unless unlocking is inferred elsewhere. If you have an achievement unlocks table, you could join it here. Otherwise, only possible to count sessions per game."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.users (
user_id character varying(64) NOT NULL, -- unique identifier for the user
username character varying(50) NOT NULL UNIQUE, -- user's unique handle
email character varying(128) NOT NULL UNIQUE, -- user's email address
password_hash text NOT NULL, -- hashed password
full_name character varying(100), -- user's full name
profile_picture_url text, -- URL to the profile picture
bio text, -- short user biography
location character varying(100), -- user's location
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update
is_verified boolean NOT NULL DEFAULT false, -- verification status
PRIMARY KEY (user_id)
)
CREATE TABLE social_media.posts (
post_id character varying(64) NOT NULL, -- unique identifier for the post
user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)
content text, -- textual content of the post
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit
visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')
location_lat numeric(9,6), -- latitude of post location
location_lon numeric(9,6), -- longitude of post location
PRIMARY KEY (post_id)
)
CREATE TABLE social_media.likes (
like_id character varying(64) NOT NULL, -- unique identifier for the like
user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)
post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)
comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred
PRIMARY KEY (like_id),
CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes
CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something
)
CREATE TABLE social_media.hashtags (
hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag
tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used
PRIMARY KEY (hashtag_id)
)
CREATE TABLE social_media.post_hashtags (
post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link
post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)
hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)
PRIMARY KEY (post_hashtag_id),
CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post
)
CREATE TABLE social_media.messages (
message_id character varying(64) NOT NULL, -- unique identifier for the message
conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
content text, -- textual content of the message
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
read_at timestamp, -- timestamp when message was read by recipient(s)
PRIMARY KEY (message_id)
)
CREATE TABLE social_media.conversations (
conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated
last_message_at timestamp, -- timestamp of the last message in the conversation
is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message
group_name character varying(100), -- name of the group chat (if applicable)
PRIMARY KEY (conversation_id)
)
CREATE TABLE social_media.conversation_participants (
participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry
conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)
user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)
joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation
last_read_at timestamp, -- timestamp indicating up to when the user has read messages
PRIMARY KEY (participant_id),
CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times
)
CREATE TABLE social_media.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)
sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)
notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')
target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)
target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created
read_at timestamp, -- timestamp notification was marked as read
PRIMARY KEY (notification_id)
)
|
[
{
"role": "user",
"content": "List all users who have a non-empty bio and a profile picture URL."
},
{
"role": "assistant",
"content": "SELECT\n user_id,\n username,\n full_name,\n bio,\n profile_picture_url\nFROM social_media.users\nWHERE\n bio IS NOT NULL AND profile_picture_url IS NOT NULL;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.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_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, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )
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_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
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, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )
|
[
{
"role": "user",
"content": "List each Avalanche token's total transfer volume over the past 7 days along with its creator from token_info."
},
{
"role": "assistant",
"content": "WITH recent_transfers AS (\n SELECT\n ta.tick,\n SUM(ta.amt) AS total_volume\n FROM token_activities_avalanche ta\n WHERE ta.block_timestamp >= now() - INTERVAL '7 days'\n GROUP BY ta.tick\n)\nSELECT\n rt.tick,\n rt.total_volume,\n ti.creator\nFROM recent_transfers rt\nLEFT JOIN token_info ti\n ON rt.tick = ti.tick\n-- If token_info has multiple records per tick, pick the most recent:\n AND ti.block_timestamp = (\n SELECT MAX(block_timestamp)\n FROM token_info\n WHERE tick = rt.tick\n );"
},
{
"role": "user",
"content": "Filter to tokens where total_volume > 10000 and creator starts with '0x1'."
},
{
"role": "assistant",
"content": "WITH recent_transfers AS (\n SELECT\n ta.tick,\n SUM(ta.amt) AS total_volume\n FROM token_activities_avalanche ta\n WHERE ta.block_timestamp >= now() - INTERVAL '7 days'\n GROUP BY ta.tick\n)\nSELECT\n rt.tick,\n rt.total_volume,\n ti.creator\nFROM recent_transfers rt\nLEFT JOIN token_info ti\n ON rt.tick = ti.tick\n AND ti.block_timestamp = (\n SELECT MAX(block_timestamp)\n FROM token_info\n WHERE tick = rt.tick\n )\nWHERE rt.total_volume > 10000\n AND ti.creator LIKE '0x1%'\nORDER BY rt.total_volume DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )
CREATE TABLE legal_services.time_entries (
entry_id character varying(64) NOT NULL, -- unique identifier for the time entry
case_id character varying(64) NOT NULL, -- FK to cases table
lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)
date_worked date NOT NULL, -- date the work was performed
hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)
billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry
description text NOT NULL, -- detailed description of the work performed
is_billable boolean DEFAULT true, -- whether this time entry is billable to the client
is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice
invoice_id character varying(64), -- FK to invoices table (once billed)
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded
PRIMARY KEY (entry_id)
)
CREATE TABLE legal_services.appointments (
appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment
client_id character varying(64) NOT NULL, -- FK to clients table
lawyer_id character varying(64) NOT NULL, -- FK to lawyers table
case_id character varying(64), -- FK to cases table (optional, if related to a specific case)
start_time timestamp NOT NULL, -- scheduled start date and time
end_time timestamp NOT NULL, -- scheduled end date and time
location text, -- location of the meeting (address or virtual link)
subject character varying(255), -- subject or purpose of the appointment
notes text, -- additional notes for the appointment
status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (appointment_id)
)
|
[
{
"role": "user",
"content": "Count the total number of cases that are currently marked as 'Open'."
},
{
"role": "assistant",
"content": "SELECT COUNT(*) FROM cases WHERE status = 'Open'"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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)
)
|
[
{
"role": "user",
"content": "For each transaction ID, provide a count of unspent UTXOs."
},
{
"role": "assistant",
"content": "SELECT transaction_id, COUNT(*) FROM utxos WHERE spent = FALSE GROUP BY transaction_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.messages (
message_id character varying(64) NOT NULL, -- unique identifier for the message
conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
content text, -- textual content of the message
media_url text, -- URL to attached media (image/video)
media_type character varying(20), -- type of media ('image', 'video', null)
sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
read_at timestamp, -- timestamp when message was read by recipient(s)
PRIMARY KEY (message_id)
)
|
[
{
"role": "user",
"content": "List message IDs and their sent time for messages containing media attachments."
},
{
"role": "assistant",
"content": "SELECT message_id , sent_at FROM social_media.messages WHERE media_type IS NOT NULL"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )
CREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )
|
[
{
"role": "user",
"content": "How many conversations in total are recorded?"
},
{
"role": "assistant",
"content": "SELECT count(*) FROM conversations;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )
CREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )
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, contract_address.text, token_name.text, token_symbol.text, decimals.integer, 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 PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )
|
[
{
"role": "user",
"content": "Show the wallet address, token symbol, and the total value received by each wallet for each token. Only include wallets that have received tokens."
},
{
"role": "assistant",
"content": "SELECT w.address AS wallet_address, t.token_symbol, SUM(tt.value) AS total_received_value\nFROM web3.wallets w\nJOIN web3.token_transfers tt ON w.address = tt.to_address\nJOIN web3.tokens t ON tt.token_id = t.token_id\nGROUP BY w.address, t.token_symbol\nORDER BY w.address, t.token_symbol;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )
CREATE TABLE government_services.applications ( application_id text PRIMARY KEY, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )
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 PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )
CREATE TABLE government_services.employees ( employee_id text PRIMARY KEY, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )
CREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )
CREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )
|
[
{
"role": "user",
"content": "For each employee, retrieve their full name and the number of appointments scheduled for them in the next 7 days, including employees with no appointments."
},
{
"role": "assistant",
"content": "SELECT e.first_name || ' ' || e.last_name AS full_name,\n COUNT(a.appointment_id) AS appointment_count\nFROM government_services.employees e\nLEFT JOIN government_services.appointments a\n ON e.employee_id = a.employee_id\n AND a.scheduled_start_time BETWEEN now() AND now() + INTERVAL '7 days'\nGROUP BY e.first_name, e.last_name;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )
CREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )
CREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )
CREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )
CREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )
CREATE TABLE transportation.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )
CREATE TABLE transportation.fuel_logs ( fuel_log_id text PRIMARY KEY, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading int, location_id text )
CREATE TABLE transportation.bookings ( booking_id text PRIMARY KEY, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )
|
[
{
"role": "user",
"content": "Retrieve the vehicle_id, make, model, and the next_service_due_date for each vehicle based on the most recent maintenance log."
},
{
"role": "assistant",
"content": "SELECT DISTINCT ON (ml.vehicle_id) v.vehicle_id, v.make, v.model, ml.next_service_due_date FROM transportation.maintenance_logs ml JOIN transportation.vehicles v ON v.vehicle_id = ml.vehicle_id ORDER BY ml.vehicle_id, ml.service_date DESC;"
},
{
"role": "user",
"content": "Now, only include vehicles with status 'Active' and whose next_service_due_date is within the next 30 days, ordering by next_service_due_date ascending."
},
{
"role": "assistant",
"content": "SELECT v.vehicle_id, v.make, v.model, ml.next_service_due_date FROM transportation.vehicles v JOIN (SELECT DISTINCT ON (vehicle_id) vehicle_id, next_service_due_date FROM transportation.maintenance_logs ORDER BY vehicle_id, service_date DESC) ml ON v.vehicle_id = ml.vehicle_id WHERE v.status = 'Active' AND ml.next_service_due_date BETWEEN current_date AND current_date + INTERVAL '30 days' ORDER BY ml.next_service_due_date ASC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )
CREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )
CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )
CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )
CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )
|
[
{
"role": "user",
"content": "Provide a summary for each transaction ID, showing the total amount of all its unspent UTXOs."
},
{
"role": "assistant",
"content": "SELECT transaction_id, SUM(amount) FROM utxos WHERE spent = false GROUP BY transaction_id"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )
CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.trades (
trade_id character varying(64) NOT NULL, -- unique identifier for the trade
order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade
buyer_id character varying(64) NOT NULL, -- identifier of the buyer
seller_id character varying(64) NOT NULL, -- identifier of the seller
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade
price numeric(38,14) NOT NULL, -- price per unit of the asset
traded_at timestamp NOT NULL, -- time when the trade was executed
PRIMARY KEY (trade_id)
)
CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )
CREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )
CREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )
CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )
CREATE TABLE trading_platform.kyc_audit (
kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit
user_id character varying(64) NOT NULL, -- identifier of the user being audited
status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)
reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed
PRIMARY KEY (kyc_audit_id)
)
CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )
|
[
{
"role": "user",
"content": "Which DApps have the word 'exchange' in their description?"
},
{
"role": "assistant",
"content": "SELECT name, description\nFROM trading_platform.dapps\nWHERE description ILIKE '%exchange%';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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": "Show the transaction ID, the transaction value from the transactions table, and the sum of the value from token_transfers for all transactions that have at least one associated token transfer. Name the sum column total_token_transfer_value."
},
{
"role": "assistant",
"content": "SELECT t.transaction_id, t.value AS transaction_native_value, SUM(tt.value) AS total_token_transfer_value FROM web3.transactions t JOIN web3.token_transfers tt ON t.transaction_id = tt.transaction_id GROUP BY t.transaction_id, t.value;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE manufacturing.aircraft_models ( model_id text PRIMARY KEY, model_name text, manufacturer text, passenger_capacity int, max_range_km int, engine_type text, wingspan_m numeric, status text, first_flight_date date )
|
[
{
"role": "user",
"content": "What are the environmental impact assessments for the production of the Airbus A350 model?"
},
{
"role": "assistant",
"content": "I'm sorry, but I don't have access to data regarding the environmental impact assessments for the production of specific aircraft models like the Airbus A350. My information is limited to the technical specifications and basic details stored in the database, such as model name, manufacturer, and capacity. If you have a question related to the available data, I'd be happy to assist."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )
|
[
{
"role": "user",
"content": "How many appointments are scheduled to start tomorrow?"
},
{
"role": "assistant",
"content": "SELECT count(*) FROM government_services.appointments WHERE DATE(scheduled_start_time) = CURRENT_DATE + INTERVAL '1 day'"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )
|
[
{
"role": "user",
"content": "What is the total investment_value per fundraising round for the year 2023? Order by total investment descending."
},
{
"role": "assistant",
"content": "SELECT\n substr(investment_date,1,7) AS month,\n rounds_name,\n SUM(investment_value) AS total_investment\nFROM project_fundraising_record\nWHERE investment_date LIKE '2023-%'\nGROUP BY substr(investment_date,1,7), rounds_name\nORDER BY total_investment DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users (
user_id character varying(64) NOT NULL, -- 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.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.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": "For each asset, I want to know how many orders have the status 'filled', showing the asset symbol."
},
{
"role": "assistant",
"content": "SELECT m.value AS asset_symbol,\n COUNT(*) AS filled_order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m\n ON o.asset_id = m.asset_id\n AND m.key = 'symbol'\nWHERE o.status = 'filled'\nGROUP BY m.value;"
},
{
"role": "user",
"content": "Include assets that have zero filled orders, showing filled_order_count as 0."
},
{
"role": "assistant",
"content": "WITH asset_symbols AS (\n SELECT DISTINCT asset_id,\n value AS asset_symbol\n FROM trading_platform.metadata\n WHERE key = 'symbol'\n)\nSELECT a.asset_symbol,\n COALESCE(f.filled_order_count, 0) AS filled_order_count\nFROM asset_symbols a\nLEFT JOIN (\n SELECT asset_id,\n COUNT(*) AS filled_order_count\n FROM trading_platform.orders\n WHERE status = 'filled'\n GROUP BY asset_id\n) f\n ON a.asset_id = f.asset_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )
CREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )
CREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )
CREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )
CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )
|
[
{
"role": "user",
"content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?"
},
{
"role": "assistant",
"content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )
|
[
{
"role": "user",
"content": "For each chain, what is the average price of tokens recorded in the smart_money_token_performance table?"
},
{
"role": "assistant",
"content": "SELECT chain, AVG(price) AS average_token_price FROM smart_money_token_performance GROUP BY chain;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.train_cars ( car_id.text, train_id.text, car_number.text, car_type.text, class.text, capacity.integer, features.text )
|
[
{
"role": "user",
"content": "What is the fuel efficiency of the train car with car_id 'TC456'?"
},
{
"role": "assistant",
"content": "I'm sorry, but I don't have access to information about the fuel efficiency of specific train cars. The data available in the train_cars table only includes details such as car_id, train_id, car_number, car_type, class, capacity, and features. If you have another question or need assistance with something else, I'm happy to help."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )
|
[
{
"role": "user",
"content": "Find appointments that are longer than 30 minutes."
},
{
"role": "assistant",
"content": "SELECT * FROM legal_services.appointments WHERE end_time IS NOT NULL AND start_time IS NOT NULL AND end_time > start_time + INTERVAL '30 minutes'"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) )
CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )
CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )
CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )
CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )
|
[
{
"role": "user",
"content": "How many likes were given to comments in June 2024?"
},
{
"role": "assistant",
"content": "SELECT COUNT(*) AS comment_likes_count\nFROM social_media.likes\nWHERE comment_id IS NOT NULL \n AND DATE_TRUNC('month', created_at) = '2024-06-01';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )
|
[
{
"role": "user",
"content": "How many beneficiaries were added on each unique date?"
},
{
"role": "assistant",
"content": "SELECT DATE(added_at), COUNT(*) FROM insurance.policy_beneficiaries GROUP BY DATE(added_at);"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )
CREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )
CREATE TABLE hospitality_technology.staff ( staff_id.text, property_id.text, first_name.text, last_name.text, position.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, is_active.boolean, access_level.integer, manager_id.text, created_at.timestamp )
CREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )
CREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )
CREATE TABLE hospitality_technology.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )
|
[
{
"role": "user",
"content": "List all rooms that have a 'Jacuzzi' feature, including the room_number, property_id, type_name, and base_rate."
},
{
"role": "assistant",
"content": "SELECT r.room_number,\n r.property_id,\n rt.type_name,\n rt.base_rate\nFROM hospitality_technology.rooms AS r\nJOIN hospitality_technology.room_types AS rt\n ON r.room_type_id = rt.room_type_id\n AND r.property_id = rt.property_id\nWHERE r.features ILIKE '%Jacuzzi%';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )
CREATE TABLE transportation.maintenance_logs ( log_id text, vehicle_id text, service_date date, odometer_reading integer, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )
CREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )
CREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )
CREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )
|
[
{
"role": "user",
"content": "For each trip, can you show the trip_id, number of passengers, and the make and model of the assigned vehicle?"
},
{
"role": "assistant",
"content": "SELECT b.trip_id, COUNT(b.passenger_id) AS passenger_count, v.make, v.model\nFROM transportation.bookings b\nJOIN transportation.vehicles v ON b.trip_id IN (\n SELECT DISTINCT trip_id FROM transportation.fuel_logs WHERE vehicle_id = v.vehicle_id\n)\nGROUP BY b.trip_id, v.make, v.model;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )
CREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )
CREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )
CREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )
|
[
{
"role": "user",
"content": "How many likes have been received by public posts, grouped by media_type? Please show media_type and the count of likes for each."
},
{
"role": "assistant",
"content": "SELECT p.media_type,\n COUNT(l.like_id) AS like_count\nFROM social_media.posts p\nJOIN social_media.likes l\n ON p.post_id = l.post_id\nWHERE p.visibility = 'public'\nGROUP BY p.media_type\nORDER BY like_count DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )
CREATE TABLE government_services.services ( service_id.text, agency_id.text, service_name.text, description.text, category.text, eligibility_criteria.text, standard_fee.numeric, average_processing_time_days.integer, is_active.boolean, online_application_url.text )
CREATE TABLE government_services.applications ( application_id.text, citizen_id.text, service_id.text, submitted_at.timestamp, status.text, last_updated_at.timestamp, assigned_employee_id.text, decision_date.date, notes.text, reference_number.text )
CREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp )
CREATE TABLE government_services.payments ( payment_id.text, application_id.text, citizen_id.text, service_id.text, amount.numeric, currency.text, payment_method.text, payment_provider_reference.text, payment_timestamp.timestamp, status.text, notes.text )
CREATE TABLE government_services.employees ( employee_id.text, agency_id.text, first_name.text, last_name.text, job_title.text, department.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, access_level.text, manager_employee_id.text )
CREATE TABLE government_services.service_locations ( location_id.text, agency_id.text, location_name.text, address.text, city.text, state.text, postal_code.text, latitude.numeric, longitude.numeric, operating_hours.text, contact_phone.text, is_accessible.boolean )
CREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text )
CREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text )
|
[
{
"role": "user",
"content": "Find the names and addresses of service locations where no appointments have been scheduled."
},
{
"role": "assistant",
"content": "SELECT sl.location_name, sl.address FROM government_services.service_locations sl LEFT JOIN government_services.appointments a ON sl.location_id = a.location_id WHERE a.appointment_id IS NULL;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )
CREATE TABLE government_services.services ( service_id.text, agency_id.text, service_name.text, description.text, category.text, eligibility_criteria.text, standard_fee.numeric, average_processing_time_days.integer, is_active.boolean, online_application_url.text )
|
[
{
"role": "user",
"content": "Show the full names and contact emails of all citizens who have applied for services with a standard fee greater than 100."
},
{
"role": "assistant",
"content": "SELECT c.first_name || ' ' || c.last_name AS full_name, c.contact_email\nFROM government_services.citizens c\nJOIN government_services.services s ON c.citizen_id IS NOT NULL -- Replace with actual application linking table if exists\nWHERE s.standard_fee > 100;"
}
] |
You are an expert in writing database language. You 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: 'inv:<inventory_record_id>'. Example: HSET inv:INVREC500 component_id "component:WINGBOLT" quantity 5000 location_warehouse "WH3" batch_number "BCH778899" ... Consider Sorted Set by expiry date: ZADD component_expiry:<component_id> <expiry_timestamp> <inventory_record_id>.
|
[
{
"role": "user",
"content": "Can you help me retrieve the inventory details for a specific component ID, including the quantity and warehouse location?"
},
{
"role": "assistant",
"content": "HGETALL inv:<inventory_record_id>"
},
{
"role": "user",
"content": "Can you also include the batch number for that inventory record?"
},
{
"role": "assistant",
"content": "HGETALL inv:<inventory_record_id>"
},
{
"role": "user",
"content": "If I want to check the expiry date for this component, how can I retrieve that information?"
},
{
"role": "assistant",
"content": "ZRANGE component_expiry:<component_id> 0 -1 WITHSCORES"
},
{
"role": "user",
"content": "Can you filter the results to show only inventory records with an expiry date after a specific timestamp?"
},
{
"role": "assistant",
"content": "ZRANGEBYSCORE component_expiry:<component_id> <specific_timestamp> +inf WITHSCORES"
}
] |
You are an expert in writing database language. You 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 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_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_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_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": "For wallet address '0xWalletA', list the ERC20 tokens held, showing contract address and amount."
},
{
"role": "assistant",
"content": "SELECT contract_address, amount FROM erc20_balances WHERE wallet_address = '0xWalletA';"
},
{
"role": "user",
"content": "Add the token symbol and name for these tokens."
},
{
"role": "assistant",
"content": "SELECT eb.contract_address, CAST(eb.amount AS DECIMAL) AS raw_amount, tm.symbol, tm.name FROM erc20_balances AS eb JOIN token_metas AS tm ON eb.contract_address = tm.contract_address WHERE eb.wallet_address = '0xWalletA';"
},
{
"role": "user",
"content": "Show the latest USD price for each token and calculate the total USD value for each holding. Order by USD value descending."
},
{
"role": "assistant",
"content": "SELECT eb.contract_address, CAST(eb.amount AS DECIMAL) AS raw_amount, tm.symbol, tm.name, tpl.price, (CAST(eb.amount AS DECIMAL) / POWER(10, tm.decimals) * tpl.price) AS usd_value FROM erc20_balances AS eb JOIN token_metas AS tm ON eb.contract_address = tm.contract_address JOIN token_prices_latest AS tpl ON tm.contract_address = tpl.address WHERE eb.wallet_address = '0xWalletA' ORDER BY usd_value DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )
CREATE TABLE legal_services.lawyers ( lawyer_id text, first_name text, last_name text, bar_number text, firm_id text, email text, phone text, specialization text, hire_date timestamp, is_partner boolean )
CREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )
CREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )
CREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )
CREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )
|
[
{
"role": "user",
"content": "Show me all time entries where the hours spent is greater than 5."
},
{
"role": "assistant",
"content": "SELECT entry_id, date_worked, hours_spent, description FROM legal_services.time_entries WHERE hours_spent > 5;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.stations ( station_id text, station_name text, city text, state_province text, country_code text, address text, timezone text, number_of_platforms integer, created_at timestamp, last_updated_at timestamp )
|
[
{
"role": "user",
"content": "What is the schedule of trains arriving at station with ID 'ST789' tomorrow?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide the train schedule for station ID 'ST789' as this information is not available in the current database. The table only contains details about station attributes such as name, location, and number of platforms. For train schedules, please refer to the relevant train service provider or timetable database."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )
|
[
{
"role": "user",
"content": "Show me the names and phone numbers of all law firms founded in the same city."
},
{
"role": "assistant",
"content": "SELECT lf1.firm_name AS firm1_name, lf1.phone AS firm1_phone, lf2.firm_name AS firm2_name, lf2.phone AS firm2_phone, lf1.address \nFROM legal_services.law_firms lf1\nJOIN legal_services.law_firms lf2 ON lf1.address = lf2.address AND lf1.firm_id < lf2.firm_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
|
[
{
"role": "user",
"content": "List each user along with the wallet_id of their first created wallet."
},
{
"role": "assistant",
"content": "SELECT\n m.user_id,\n w.wallet_id AS first_wallet_id\nFROM (\n SELECT user_id, MIN(created_at) AS first_created_at\n FROM web3.wallets\n GROUP BY user_id\n) AS m\nJOIN web3.wallets AS w\n ON w.user_id = m.user_id\n AND w.created_at = m.first_created_at;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )
CREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )
CREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )
CREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )
|
[
{
"role": "user",
"content": "Show me the total fuel quantity and cost for each route, grouped by route number, only for trips that have associated fuel logs."
},
{
"role": "assistant",
"content": "SELECT r.route_number, SUM(f.quantity) AS total_quantity, SUM(f.total_cost) AS total_cost\nFROM transportation.fuel_logs f\nJOIN transportation.routes r ON f.trip_id IS NOT NULL AND f.trip_id IN (\n SELECT DISTINCT trip_id FROM transportation.fuel_logs\n)\nJOIN transportation.bookings b ON f.trip_id = b.trip_id\nWHERE r.route_id = b.trip_id\nGROUP BY r.route_number;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )
CREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )
CREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )
CREATE TABLE transportation.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text )
CREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )
CREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )
CREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )
CREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )
|
[
{
"role": "user",
"content": "What was the total quantity and total cost of 'Gasoline' fuel logged in the year 2023?"
},
{
"role": "assistant",
"content": "SELECT SUM(quantity) , SUM(total_cost) FROM transportation.fuel_logs WHERE fuel_type = 'Gasoline' AND EXTRACT(YEAR FROM log_timestamp) = 2023"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.maintenance_records (
record_id character varying(64) NOT NULL, -- Unique identifier for the maintenance record
asset_id character varying(64) NOT NULL, -- ID of the asset being maintained (train_id, car_id, platform_id, etc.)
asset_type character varying(32) NOT NULL, -- Type of asset ('Train', 'Car', 'Platform', 'Track')
maintenance_type character varying(128) NOT NULL, -- e.g., 'Scheduled Inspection', 'Repair', 'Cleaning'
staff_id character varying(64), -- Staff member performing/overseeing maintenance
start_datetime timestamp NOT NULL, -- When maintenance started
end_datetime timestamp, -- When maintenance completed (nullable if ongoing)
description text NOT NULL, -- Details of the maintenance performed
cost numeric(12, 2), -- Cost associated with the maintenance
status character varying(32) NOT NULL DEFAULT 'Completed', -- e.g., 'Scheduled', 'In Progress', 'Completed', 'Cancelled'
PRIMARY KEY (record_id),
FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id)
)
|
[
{
"role": "user",
"content": "What are the qualifications or training history of the staff member who performed the maintenance with record_id 'REC123'?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information about the qualifications or training history of staff members as this data is not stored in the maintenance_records table. This table only contains details about maintenance activities, such as asset information, maintenance type, dates, and costs. If you have another question or need assistance with data available in this table, I'm happy to help."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )
|
[
{
"role": "user",
"content": "For each service location, find the nearest accessible service location. Show the location_id, location_name, nearest_location_id, and the distance."
},
{
"role": "assistant",
"content": "SELECT l.location_id,\n l.location_name,\n nearest.location_id AS nearest_location_id,\n SQRT(POWER(l.latitude - nearest.latitude, 2) + POWER(l.longitude - nearest.longitude, 2)) AS distance\nFROM service_locations l\nJOIN LATERAL (\n SELECT sl.location_id, sl.latitude, sl.longitude\n FROM service_locations sl\n WHERE sl.location_id <> l.location_id\n AND sl.is_accessible = TRUE\n ORDER BY POWER(l.latitude - sl.latitude, 2) + POWER(l.longitude - sl.longitude, 2)\n LIMIT 1\n) AS nearest ON TRUE;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.policies (
policy_id character varying(64) NOT NULL, -- unique identifier for the policy
customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)
product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)
agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)
policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number
start_date date NOT NULL, -- date the policy coverage begins
end_date date NOT NULL, -- date the policy coverage ends
premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term
coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered
deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in
status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending
issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued
cancellation_date date,
cancellation_reason text,
PRIMARY KEY (policy_id)
)
|
[
{
"role": "user",
"content": "Find all policies that were cancelled due to 'Non-payment'. Show the policy number, cancellation date, and premium amount for these policies."
},
{
"role": "assistant",
"content": "SELECT policy_number , cancellation_date , premium_amount FROM insurance.policies WHERE status = 'Cancelled' AND cancellation_reason = 'Non-payment'"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.citizens (
citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen
national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
date_of_birth date NOT NULL,
gender character varying(20),
primary_address text NOT NULL, -- full primary residential address
contact_email character varying(128) UNIQUE,
contact_phone character varying(32),
registration_date timestamp NOT NULL, -- when the citizen profile was created
is_verified boolean DEFAULT false, -- whether identity has been officially verified
PRIMARY KEY (citizen_id)
)
|
[
{
"role": "user",
"content": "Provide a count of citizens registered per calendar year."
},
{
"role": "assistant",
"content": "SELECT CAST(EXTRACT(YEAR FROM registration_date) AS INTEGER) AS registration_year, COUNT(*) AS citizen_count FROM government_services.citizens GROUP BY 1 ORDER BY 1;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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)
)
|
[
{
"role": "user",
"content": "Calculate the average number of days between when an incident occurred and when the claim was reported, but only for claims that were settled in the year 2023."
},
{
"role": "assistant",
"content": "SELECT\n AVG(EXTRACT(EPOCH FROM (reported_date - incident_date)) / 86400.0)::numeric(10, 2)\nFROM\n insurance.claims\nWHERE\n settlement_date IS NOT NULL AND EXTRACT(YEAR FROM settlement_date) = 2023;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
|
[
{
"role": "user",
"content": "Find all insurance providers that offer both HMO and PPO plans and list the provider name along with the corresponding HMO and PPO plan IDs."
},
{
"role": "assistant",
"content": "SELECT h.insurance_provider,\n h.plan_id AS hmo_plan_id,\n p.plan_id AS ppo_plan_id\nFROM healthcare.insurance_plans h\nJOIN healthcare.insurance_plans p\n ON h.insurance_provider = p.insurance_provider\nWHERE h.plan_type = 'HMO'\n AND p.plan_type = 'PPO';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.lawyers (
lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer
first_name character varying(100) NOT NULL, -- lawyer's first name
last_name character varying(100) NOT NULL, -- lawyer's last name
bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number
firm_id character varying(64), -- FK to law_firms table
email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email
phone character varying(32), -- lawyer's contact phone number
specialization text, -- areas of legal expertise
hire_date timestamp NOT NULL, -- date the lawyer was hired or joined
is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner
PRIMARY KEY (lawyer_id)
)
|
[
{
"role": "user",
"content": "How many lawyers who are partners were hired in each year? Show the hire year and the count."
},
{
"role": "assistant",
"content": "SELECT strftime('%Y', hire_date) AS hire_year , count(lawyer_id) FROM legal_services.lawyers WHERE is_partner = true GROUP BY hire_year"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
|
[
{
"role": "user",
"content": "Find patients whose emergency_contact_phone matches another patient's phone_number and show both patients' IDs, full names, and the shared phone number."
},
{
"role": "assistant",
"content": "SELECT p1.patient_id AS contact_of_id,\n p1.first_name || ' ' || p1.last_name AS contact_of_name,\n p2.patient_id AS phone_owner_id,\n p2.first_name || ' ' || p2.last_name AS phone_owner_name,\n p1.emergency_contact_phone AS shared_phone\nFROM healthcare.patients p1\nJOIN healthcare.patients p2\n ON p1.emergency_contact_phone = p2.phone_number\nWHERE p1.emergency_contact_phone IS NOT NULL;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )
|
[
{
"role": "user",
"content": "How many documents were uploaded in the year 2023?"
},
{
"role": "assistant",
"content": "SELECT count(*) FROM government_services.documents WHERE date_part('year', upload_timestamp) = 2023;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
// Use Hashes to store station details. Key format: station:<station_id>
// Example:
// HSET station:station_xyz station_id "station_xyz" station_name "Grand Central Terminal" city "New York" state_province "NY" country_code "USA" address "89 E 42nd St..." timezone "America/New_York" number_of_platforms 44 created_at "2023-01-15T10:00:00Z" last_updated_at "2023-10-28T15:30:00Z"
// To quickly find stations by city (optional index):
// SADD stations:city:NewYork station:station_xyz
// Use Hashes for platform details. Key format: platform:<platform_id>
// HSET platform:plat_123 platform_id "plat_123" station_id "station_xyz" platform_number "1A" track_number "T1" status "Operational" length_meters 250.50 accessible 1
// To link platforms to stations (optional):
// SADD station:station_xyz:platforms platform:plat_123 platform:plat_456
// Use Hashes for train details. Key format: train:<train_id>
// HSET train:train_789 train_id "train_789" train_number "Acela 2151" model "Siemens Velaro" ... status "Active" ...
// To find train by train_number (optional index):
// SET train_number:"Acela 2151" train:train_789
// Use Hashes for car details. Key format: car:<car_id>
// HSET car:car_abc car_id "car_abc" train_id "train_789" car_number "C3" car_type "Passenger" class "Business" capacity 60 features "WiFi,Power Outlet"
// To link cars to trains (optional):
// SADD train:train_789:cars car:car_abc car:car_def
// Use Hashes for route details. Key format: route:<route_id>
// HSET route:route_ne_corr route_id "route_ne_corr" route_name "Northeast Corridor" ... origin_station_id "station_bos" ... is_active 1
// Use Hashes for details. Key format: route_station:<route_station_id>
// HSET route_station:rs_ne_1 route_station_id "rs_ne_1" route_id "route_ne_corr" station_id "station_bos" sequence_order 1 ...
// To find stops for a route, use a Sorted Set (score by sequence_order):
// ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1
// ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2
// Use Hashes for passenger details. Key format: passenger:<passenger_id>
// HSET passenger:pass_pqr passenger_id "pass_pqr" first_name "Alice" last_name "Smith" email "alice.smith@example.com" ...
// To find passenger by email (optional index):
// SET passenger_email:"alice.smith@example.com" passenger:pass_pqr
// Use Hashes for booking details. Key format: booking:<booking_id>
// HSET booking:book_zyx booking_id "book_zyx" passenger_id "pass_pqr" schedule_id "sched_1122" ... status "Confirmed" ...
// To link bookings to passengers/schedules (optional):
// SADD passenger:pass_pqr:bookings booking:book_zyx
// SADD schedule:sched_1122:bookings booking:book_zyx
// Use Hashes for ticket details. Key format: ticket:<ticket_id>
// HSET ticket:tkt_1a2b ticket_id "tkt_1a2b" booking_id "book_zyx" car_id "car_abc" seat_number "12A" ... is_checked_in 0 ...
// To link tickets to bookings (optional):
// SADD booking:book_zyx:tickets ticket:tkt_1a2b
|
[
{
"role": "user",
"content": "能否帮我统计特定车站(station_id 为 'station_xyz')的所有平台数量?"
},
{
"role": "assistant",
"content": "SCARD station:station_xyz:platforms"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )
|
[
{
"role": "user",
"content": "For each network, list the deployer address and the number of contracts they have deployed, ordered from most to least."
},
{
"role": "assistant",
"content": "SELECT network_id, deployer_address, COUNT(*) AS deployed_contracts FROM web3.contracts GROUP BY network_id, deployer_address ORDER BY network_id, deployed_contracts DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )
|
[
{
"role": "user",
"content": "List all law firms that do not have a managing partner listed."
},
{
"role": "assistant",
"content": "SELECT firm_name, phone, address, founded_date\nFROM legal_services.law_firms\nWHERE managing_partner_id IS NULL;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.maintenance_records ( record_id.text, asset_id.text, asset_type.text, maintenance_type.text, staff_id.text, start_datetime.timestamp, end_datetime.timestamp, description.text, cost.numeric, status.text )
|
[
{
"role": "user",
"content": "What is the detailed repair history of the equipment used by the staff with staff_id 'STAFF123' during maintenance tasks?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the detailed repair history of equipment used by staff members. The data in the maintenance_records table only includes information about maintenance tasks, such as record_id, asset_id, maintenance type, and staff_id, but does not cover equipment repair histories."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
CREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )
CREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )
|
[
{
"role": "user",
"content": "List the full names of patients who have had at least one appointment scheduled with a doctor, along with the medication names they have been prescribed. Please include only patients who have both an appointment and at least one corresponding medication."
},
{
"role": "assistant",
"content": "SELECT DISTINCT p.first_name, p.last_name, m.medication_name\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nJOIN healthcare.medications m ON m.medication_id IN (\n SELECT medication_id FROM healthcare.medications\n) -- Placeholder, since no direct prescription table or mapping is given\nWHERE a.status = 'scheduled';"
},
{
"role": "user",
"content": "Actually, could you also include the appointment time in the results?"
},
{
"role": "assistant",
"content": "SELECT DISTINCT p.first_name, p.last_name, a.appointment_time, m.medication_name\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nJOIN healthcare.medications m ON m.medication_id IN (\n SELECT medication_id FROM healthcare.medications\n)\nWHERE a.status = 'scheduled';"
},
{
"role": "user",
"content": "The medication names are not matching with the appointments, I think there is no direct link. Can you just give me, for each patient who has at least one scheduled appointment, all their appointment times and their last names, without including medication info?"
},
{
"role": "assistant",
"content": "SELECT DISTINCT p.first_name, p.last_name, a.appointment_time\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nWHERE a.status = 'scheduled';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )
CREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )
CREATE TABLE legal_services.documents ( document_id text PRIMARY KEY, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version int, description text )
|
[
{
"role": "user",
"content": "Count the number of law firms founded in each decade. Show the decade (e.g., 1990s, 2000s) and the count."
},
{
"role": "assistant",
"content": "SELECT CONCAT(FLOOR(EXTRACT(YEAR FROM founded_date) / 10) * 10, 's') AS decade, COUNT(*) AS firm_count FROM law_firms WHERE founded_date IS NOT NULL GROUP BY decade ORDER BY decade;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.events (
event_id character varying(64) NOT NULL, -- unique identifier for the event
contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event
event_name character varying(128) NOT NULL, -- name of the event
data text NOT NULL, -- data payload of the event
emitted_at timestamp NOT NULL, -- time when the event was emitted
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event
log_index integer NOT NULL, -- index of the event log in the transaction
PRIMARY KEY (event_id)
)
CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )
CREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )
CREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
|
[
{
"role": "user",
"content": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred."
},
{
"role": "assistant",
"content": "SELECT E.event_id, E.event_name, E.transaction_id, T.status, T.value FROM web3.events AS E JOIN web3.transactions AS T ON E.transaction_id = T.transaction_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.documents (
document_id character varying(64) NOT NULL, -- unique identifier for the document instance
application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)
citizen_id character varying(64) NOT NULL, -- FK to citizens table
document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate
file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)
upload_timestamp timestamp NOT NULL,
expiry_date date,
verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected
verified_by_employee_id character varying(64), -- FK to employees table
verification_timestamp timestamp,
PRIMARY KEY (document_id)
)
|
[
{
"role": "user",
"content": "Count the number of documents for each unique document type."
},
{
"role": "assistant",
"content": "SELECT document_type, COUNT(*) AS document_count FROM government_services.documents GROUP BY document_type ORDER BY document_count DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )
|
[
{
"role": "user",
"content": "How many messages include a media attachment?"
},
{
"role": "assistant",
"content": "SELECT COUNT(*) FROM social_media.messages WHERE media_url IS NOT NULL AND TRIM(media_url) <> '';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.appointments (
appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment
patient_id character varying(64) NOT NULL, -- FK to patients table
doctor_id character varying(64) NOT NULL, -- FK to doctors table
appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment
duration_minutes integer NOT NULL, -- expected duration in minutes
reason text, -- reason for the visit
status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show
location_id character varying(64), -- FK to a potential locations/clinics table
notes text, -- notes related to scheduling
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (appointment_id)
)
CREATE TABLE healthcare.medical_records (
record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry
patient_id character varying(64) NOT NULL, -- FK to patients table
appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)
doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)
record_date timestamp with time zone NOT NULL, -- date the record/observation was made
chief_complaint text, -- patient's primary reason for visit
present_illness_history text, -- detailed history of the current issue
past_medical_history text, -- relevant past conditions/surgeries
physical_examination_notes text, -- findings from the physical exam
assessment text, -- doctor's assessment/diagnosis summary
treatment_plan text, -- planned course of action
vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (record_id)
)
CREATE TABLE healthcare.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": "For each scheduled appointment, list the appointment_id, appointment_time, patient_id, and the name of the patient's primary insurance plan. Only include appointments that have not been cancelled."
},
{
"role": "assistant",
"content": "SELECT a.appointment_id,\n a.appointment_time,\n a.patient_id,\n ip.plan_name\nFROM healthcare.appointments a\nJOIN healthcare.patient_insurance pi\n ON a.patient_id = pi.patient_id\n AND pi.is_primary = TRUE\nJOIN healthcare.insurance_plans ip\n ON pi.plan_id = ip.plan_id\nWHERE a.status != 'Cancelled';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )
CREATE TABLE transportation.trips (
trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance
route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)
vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used
driver_id character varying(64) NOT NULL, -- identifier of the driver operating
scheduled_departure timestamp with time zone NOT NULL, -- planned departure time
actual_departure timestamp with time zone, -- actual departure time
scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time
actual_arrival timestamp with time zone, -- actual arrival time
origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)
destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)
status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled
passenger_count integer, -- number of passengers (if applicable)
cargo_manifest_id character varying(64), -- link to cargo details (if applicable)
PRIMARY KEY (trip_id)
)
CREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )
CREATE TABLE transportation.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )
|
[
{
"role": "user",
"content": "List all maintenance logs for vehicles that had 'Oil Change' service in the last 3 months, showing vehicle ID, service date, and cost."
},
{
"role": "assistant",
"content": "SELECT vehicle_id, service_date, cost FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months';"
},
{
"role": "user",
"content": "Can you include the mechanic name and show only services that cost more than $100?"
},
{
"role": "assistant",
"content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100;"
},
{
"role": "user",
"content": "Actually, I need to see the vehicle make and model as well. Can you include that information?"
},
{
"role": "assistant",
"content": "Sorry, I can't include vehicle make and model as those fields aren't present in the provided table schemas. The maintenance_logs table only contains vehicle_id but not make/model information."
},
{
"role": "user",
"content": "Then just add the odometer reading to the previous query and order by the most recent services first."
},
{
"role": "assistant",
"content": "SELECT vehicle_id, service_date, cost, mechanic_name, odometer_reading FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100 ORDER BY service_date DESC;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE manufacturing.aircraft_models ( model_id text, model_name text, manufacturer text, passenger_capacity integer, max_range_km integer, engine_type text, wingspan_m numeric, status text, first_flight_date date )
|
[
{
"role": "user",
"content": "What are the safety ratings or crash statistics for the Boeing 787 Dreamliner?"
},
{
"role": "assistant",
"content": "I'm sorry, but I don't have access to safety ratings or crash statistics for specific aircraft models like the Boeing 787 Dreamliner. My data is limited to the information in the aircraft_models table, which includes details such as model name, manufacturer, passenger capacity, and technical specifications. For safety-related information, I recommend consulting official aviation authorities or safety reports."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text )
|
[
{
"role": "user",
"content": "Find pairs of notifications for the same citizen where one was sent via 'Email' and another via 'SMS'. Display citizen_id, email_notification_id, sms_notification_id, email_sent_at, and sms_sent_at."
},
{
"role": "assistant",
"content": "SELECT e.citizen_id,\n e.notification_id AS email_notification_id,\n s.notification_id AS sms_notification_id,\n e.sent_at AS email_sent_at,\n s.sent_at AS sms_sent_at\nFROM government_services.notifications e\nJOIN government_services.notifications s\n ON e.citizen_id = s.citizen_id\n AND e.channel = 'Email'\n AND s.channel = 'SMS';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )
|
[
{
"role": "user",
"content": "Which routes have their origin and destination in the same city? Show the route number, description, and the origin and destination location IDs."
},
{
"role": "assistant",
"content": "SELECT r.route_number, r.description, r.origin_location_id, r.destination_location_id\nFROM transportation.routes r\nJOIN transportation.routes r2 ON r.origin_location_id = r2.destination_location_id AND r.route_id = r2.route_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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) )
|
[
{
"role": "user",
"content": "List the reference number and status for all applications, including the registration date of the citizen who submitted it."
},
{
"role": "assistant",
"content": "SELECT a.reference_number, a.status, c.registration_date FROM government_services.applications AS a JOIN citizens AS c ON a.citizen_id = c.citizen_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.messages ( message_id 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": "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 expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.maintenance_records ( record_id text, asset_id text, asset_type text, maintenance_type text, staff_id text, start_datetime timestamp, end_datetime timestamp, description text, cost numeric, status text )
|
[
{
"role": "user",
"content": "What are the personal contact details of the staff member associated with staff_id 'STAFF789' who worked on a specific maintenance record?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide personal contact details of staff members as this information is not stored in the maintenance_records table and is outside the scope of the available data."
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.stations ( station_id text PRIMARY KEY, station_name text, city text, state_province text, country_code text, address text, timezone text, number_of_platforms int, created_at timestamp, last_updated_at timestamp )
|
[
{
"role": "user",
"content": "What is the maintenance schedule for the platforms at the station with ID 'ST234' for the next month?"
},
{
"role": "assistant",
"content": "I'm sorry, but I don't have access to the maintenance schedule for the platforms at any station. The data I have only includes basic station information such as station ID, name, location, and number of platforms. For maintenance schedules, you may need to contact the station management or relevant authorities."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )
|
[
{
"role": "user",
"content": "For each transaction, find the next transaction initiated by the same sender. List the original transaction_id, the next transaction_id, the sender address, and the time difference in hours between them."
},
{
"role": "assistant",
"content": "SELECT t1.transaction_id AS original_tx,\n t2.transaction_id AS next_tx,\n t1.from_address,\n EXTRACT(EPOCH FROM (t2.timestamp - t1.timestamp)) / 3600 AS hours_diff\nFROM transactions t1\nJOIN transactions t2\n ON t1.from_address = t2.from_address\n AND t2.timestamp = (\n SELECT MIN(timestamp)\n FROM transactions t3\n WHERE t3.from_address = t1.from_address\n AND t3.timestamp > t1.timestamp\n );"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 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_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_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 token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.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 the contract address, symbol, and current total supply for all Avalanche tokens from token_balances_avalanche."
},
{
"role": "assistant",
"content": "SELECT tick AS contract_address, tick AS symbol, SUM(total_supply) AS current_total_supply\nFROM token_balances_avalanche\nGROUP BY tick;"
},
{
"role": "user",
"content": "Now, include the latest price for each token by joining with token_prices_latest."
},
{
"role": "assistant",
"content": "SELECT tba.tick AS contract_address, tba.tick AS symbol, SUM(tba.total_supply) AS current_total_supply, tpl.price AS latest_price\nFROM token_balances_avalanche tba\nLEFT JOIN token_prices_latest tpl\n ON tpl.address = tba.tick AND tpl.blockchain = 'Avalanche'\nGROUP BY tba.tick, tpl.price;"
},
{
"role": "user",
"content": "Filter out tokens where the current_total_supply is less than 1000 and sort the results by latest_price descending."
},
{
"role": "assistant",
"content": "SELECT tba.tick AS contract_address, tba.tick AS symbol, SUM(tba.total_supply) AS current_total_supply, tpl.price AS latest_price\nFROM token_balances_avalanche tba\nLEFT JOIN token_prices_latest tpl\n ON tpl.address = tba.tick AND tpl.blockchain = 'Avalanche'\nGROUP BY tba.tick, tpl.price\nHAVING SUM(tba.total_supply) >= 1000\nORDER BY tpl.price DESC;"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE manufacturing.component_inventory (
inventory_record_id character varying(64) NOT NULL, -- unique ID for this inventory record/batch
component_id character varying(64) NOT NULL, -- FK to the component
quantity integer NOT NULL, -- number of units of this component in stock for this batch
location_warehouse character varying(100), -- warehouse identifier
location_bin character varying(100), -- specific bin or shelf location
received_date timestamp NOT NULL, -- when this batch was received
expiry_date date, -- expiry date if applicable (e.g., for sealants, adhesives)
batch_number character varying(100), -- supplier batch number
last_updated timestamp NOT NULL, -- timestamp of the last update to this record
PRIMARY KEY (inventory_record_id)
)
|
[
{
"role": "user",
"content": "What is the purchase price of the components in a specific batch with batch_number 'BATCH123'?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the purchase price of components as this data is not stored in the component_inventory table. If you have other questions or need assistance with data available in the table, such as quantity or location, I'm happy to help."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.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 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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
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) )
|
[
{
"role": "user",
"content": "Show me all reservations with their reservation_id, room_number, room status, and check_in_date."
},
{
"role": "assistant",
"content": "SELECT r.reservation_id,\n rm.room_number,\n rm.status AS room_status,\n r.check_in_date\nFROM hospitality_technology.reservations r\nLEFT JOIN hospitality_technology.rooms rm\n ON r.room_id = rm.room_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )
|
[
{
"role": "user",
"content": "How many unique tokens are recorded for each chain in the latest snapshot in cex_token_balance?"
},
{
"role": "assistant",
"content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n)\nSELECT \n chain, \n COUNT(DISTINCT token_symbol) AS unique_token_count\nFROM cex_token_balance c\nJOIN latest_snapshot l ON c.snapshot_time = l.max_time\nGROUP BY chain\nORDER BY unique_token_count DESC;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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.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.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": "List the usernames and user IDs of all users whose bio contains the word 'developer'."
},
{
"role": "assistant",
"content": "SELECT user_id, username\nFROM social_media.users\nWHERE bio ILIKE '%developer%';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
|
[
{
"role": "user",
"content": "List all wallets that were created during the hour of the day which saw the highest number of wallet creations. Show the wallet ID, user ID, address, and creation timestamp."
},
{
"role": "assistant",
"content": "WITH HourlyCounts AS (\n SELECT EXTRACT(HOUR FROM created_at) AS hour, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY 1\n),\nMaxHour AS (\n SELECT hour\n FROM HourlyCounts\n ORDER BY wallet_count DESC\n LIMIT 1\n)\nSELECT wallet_id, user_id, address, created_at\nFROM web3.wallets\nWHERE EXTRACT(HOUR FROM created_at) = (SELECT hour FROM MaxHour);"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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": "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 expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )
|
[
{
"role": "user",
"content": "List the usernames of players who own at least one item from the game with title 'Game Title X'."
},
{
"role": "assistant",
"content": "SELECT DISTINCT T1.username FROM players AS T1 INNER JOIN player_inventory AS T2 ON T1.player_id = T2.player_id INNER JOIN items AS T3 ON T2.item_id = T3.item_id INNER JOIN games AS T4 ON T3.game_id = T4.game_id WHERE T4.title = 'Game Title X';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )
|
[
{
"role": "user",
"content": "For each location, count the total number of appointments scheduled. Show the location name and the count."
},
{
"role": "assistant",
"content": "SELECT T2.location_name, COUNT(T1.appointment_id) FROM government_services.appointments AS T1 JOIN locations AS T2 ON T1.location_id = T2.location_id GROUP BY T2.location_name;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )
|
[
{
"role": "user",
"content": "List all claim documents where the description contains the word 'invoice'."
},
{
"role": "assistant",
"content": "SELECT document_id, claim_id, file_name, description FROM insurance.claim_documents WHERE description ILIKE '%invoice%';"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )
|
[
{
"role": "user",
"content": "How many appointments have been scheduled on weekends?"
},
{
"role": "assistant",
"content": "SELECT COUNT(*) AS weekend_appointments\nFROM legal_services.appointments\nWHERE EXTRACT(DOW FROM start_time) IN (0,6);"
}
] |
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE manufacturing.employees ( employee_id text, first_name text, last_name text, job_title text, skill_certifications text, hire_date date, assigned_line_id text, employment_status text, supervisor_employee_id text )
|
[
{
"role": "user",
"content": "What is the reason for the termination of employee with ID 'EMP789'?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the reason for an employee's termination as it is not stored in the current database table."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE financial_services.employees (
employee_id character varying(64) NOT NULL, -- unique identifier for the employee
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst
department character varying(100), -- e.g., Retail Banking, Wealth Management, IT
branch_id character varying(64), -- Identifier for the branch they work at (if applicable)
email character varying(128) NOT NULL UNIQUE,
phone_extension character varying(20),
hire_date date NOT NULL,
termination_date date, -- Date of termination, null if currently employed
manager_id character varying(64), -- Self-referencing key for manager relationship
status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave
PRIMARY KEY (employee_id),
FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists
FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)
)
|
[
{
"role": "user",
"content": "Report the number of employees for each department, broken down by their employment status."
},
{
"role": "assistant",
"content": "SELECT department, status, COUNT(*) AS employee_count FROM financial_services.employees GROUP BY department, status"
},
{
"role": "user",
"content": "Only show results for departments that have at least 10 employees in total (across all statuses)."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )
CREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )
CREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )
CREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )
|
[
{
"role": "user",
"content": "For each developer, show their name and the total number of achievements in all games they have developed."
},
{
"role": "assistant",
"content": "SELECT d.name AS developer_name, COUNT(a.achievement_id) AS total_achievements\nFROM gaming_technology.developers d\nJOIN gaming_technology.servers s ON d.developer_id = s.game_id -- There is no direct relationship, but assuming developer_id and game_id are connected\nJOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY d.developer_id, d.name;"
},
{
"role": "user",
"content": "I think the join between developers and servers is not correct, because developer_id and game_id are different types. Could you try to just show the total number of achievements across all games, and their respective developers, if possible with the current tables?"
},
{
"role": "assistant",
"content": "SELECT '-' AS developer_name, COUNT(a.achievement_id) AS total_achievements\nFROM gaming_technology.achievements a;"
},
{
"role": "user",
"content": "Can you instead list the total number of achievements available for each game_id?"
},
{
"role": "assistant",
"content": "SELECT game_id, COUNT(achievement_id) AS total_achievements\nFROM gaming_technology.achievements\nGROUP BY game_id;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 )
|
[
{
"role": "user",
"content": "How many service locations are there for each agency? List the agency ID and the count of locations."
},
{
"role": "assistant",
"content": "SELECT agency_id , count(*) FROM government_services.service_locations GROUP BY 1"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )
CREATE TABLE social_media.comments (
comment_id 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.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )
CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )
CREATE TABLE social_media.post_hashtags (
post_hashtag_id character varying(64) NOT NULL, -- 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 text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )
CREATE TABLE social_media.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 text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )
CREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )
|
[
{
"role": "user",
"content": "List all hashtags that have been used on posts created in the last 90 days. Show the tag_name and the date it was first used on a post within this period."
},
{
"role": "assistant",
"content": "SELECT h.tag_name, MIN(p.created_at) AS first_use_date_in_period FROM social_media.posts AS p JOIN social_media.post_hashtags AS ph ON p.post_id = ph.post_id JOIN social_media.hashtags AS h ON ph.hashtag_id = h.hashtag_id WHERE p.created_at >= NOW() - INTERVAL '90 days' GROUP BY h.hashtag_id, h.tag_name;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )
|
[
{
"role": "user",
"content": "For each vehicle, list the vehicle_id and the total number of trips it has performed."
},
{
"role": "assistant",
"content": "SELECT vehicle_id, COUNT(*) AS trip_count FROM transportation.trips GROUP BY vehicle_id;"
},
{
"role": "user",
"content": "Can you limit this to only vehicles that have more than 10 trips?"
},
{
"role": "assistant",
"content": "SELECT vehicle_id, COUNT(*) AS trip_count FROM transportation.trips GROUP BY vehicle_id HAVING COUNT(*) > 10;"
},
{
"role": "user",
"content": "In addition, for these vehicles, can you show the driver_id who has driven the highest number of trips for each vehicle?"
},
{
"role": "assistant",
"content": "SELECT vehicle_id, driver_id, trip_driver_count FROM (SELECT vehicle_id, driver_id, COUNT(*) AS trip_driver_count, ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY COUNT(*) DESC) as rn FROM transportation.trips GROUP BY vehicle_id, driver_id) t WHERE rn = 1 AND vehicle_id IN (SELECT vehicle_id FROM transportation.trips GROUP BY vehicle_id HAVING COUNT(*) > 10);"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )
CREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )
|
[
{
"role": "user",
"content": "For each patient, find the date of their most recent medical record and the effective date of their current primary insurance plan. Return patient_id, last_record_date, and effective_date."
},
{
"role": "assistant",
"content": "SELECT m.patient_id,\n m.last_date AS last_record_date,\n pi.effective_date\nFROM (\n SELECT patient_id,\n MAX(record_date) AS last_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) m\nJOIN healthcare.patient_insurance pi\n ON m.patient_id = pi.patient_id\nWHERE pi.is_primary = TRUE;"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.