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 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 )
| [
{
"role": "user",
"content": "List all pairs of vehicles in the same depot with different status. Include both vehicle IDs with their statuses and the depot_id."
},
{
"role": "assistant",
"content": "SELECT v1.vehicle_id AS vehicle1_id,\n v1.status AS status1,\n v2.vehicle_id AS vehicle2_id,\n v2.status AS status2,\n v1.depot_id\nFROM transportation.vehicles v1\nJOIN transportation.vehicles v2\n ON v1.depot_id = v2.depot_id\n AND v1.vehicle_id < v2.vehicle_id\n AND v1.status <> v2.status;"
}
] |
You are an expert in writing database language. You 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.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )
| [
{
"role": "user",
"content": "Show all pairs of 'Evidence' documents within the same case, listing their document names, version numbers, and the shared case_id."
},
{
"role": "assistant",
"content": "SELECT d1.case_id,\n d1.document_name AS doc1_name,\n d1.version AS doc1_version,\n d2.document_name AS doc2_name,\n d2.version AS doc2_version\nFROM legal_services.documents d1\nJOIN legal_services.documents d2\n ON d1.case_id = d2.case_id\n AND d1.document_id < d2.document_id\nWHERE d1.document_type = 'Evidence'\n AND d2.document_type = 'Evidence';"
}
] |
You are an expert in writing database language. You 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.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )
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.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, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )
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) )
CREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )
CREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )
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": "Count the number of followers for each user and show those users who have more than 100 followers, ordering by follower_count descending."
},
{
"role": "assistant",
"content": "SELECT following_user_id AS user_id,\n COUNT(*) AS follower_count\nFROM social_media.follows\nGROUP BY following_user_id\nHAVING COUNT(*) > 100\nORDER BY follower_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 text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )
| [
{
"role": "user",
"content": "List all users who signed up in 2024 and have not set a bio. Show their usernames, emails, and account creation dates."
},
{
"role": "assistant",
"content": "SELECT username, email, created_at FROM social_media.users WHERE bio IS NULL AND EXTRACT(YEAR FROM created_at) = 2024;"
}
] |
You are an expert in writing database language. You 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 varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )
CREATE TABLE erc1155_approval_for_all (
block_number bigint NOT NULL, -- Block number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction
transaction_index integer NOT NULL, -- Index of the transaction within the block
transaction_hash varchar(66) NOT NULL, -- Transaction hash
log_index integer NOT NULL, -- Log index
contract_address varchar(42) NOT NULL -- Event contract address
)
CREATE TABLE erc20_balances (
block_number bigint NOT NULL, -- Block number containing the transaction
contract_address varchar NOT NULL, -- Event contract address
wallet_address varchar NOT NULL, -- The wallet address for the contract
amount varchar NOT NULL, -- Wallet's on-chain balance at the corresponding block height
pk varchar NOT NULL -- The last string partition of the contract.
)
CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )
CREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )
CREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )
CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )
CREATE TABLE nft_collections (
blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract
contract_address varchar NOT NULL, -- Contract address(with bloom filter)
name varchar NOT NULL, -- name fields for the functionType in contract
symbol varchar NOT NULL, -- symbol fields for the functionType in contract
deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract
deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract
erc_type varchar NOT NULL, -- The type of token
owner varchar NOT NULL, -- owner fields for the functionType in contract
traits varchar NOT NULL, -- traits fields for the functionType in contract
description varchar NOT NULL, -- description fields for the functionType in contract
slug varchar NOT NULL, -- slug fields for the functionType in contract
media_info varchar NOT NULL, -- media_info fields for the functionType in contract
image_url varchar NOT NULL, -- image_url fields for the functionType in contract
banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract
updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract
banner varchar NOT NULL, -- banner fields for the functionType in contract
token_count bigint NOT NULL, -- token_count fields for the functionType in contract
floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract
floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract
floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract
pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))
)
CREATE TABLE token_prices (
uuid varchar(36) NOT NULL, -- uuid fields for the functionType in contract
blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract
address varchar(42) NOT NULL, -- address fields for the functionType in contract
decimals bigint NOT NULL, -- decimals fields for the functionType in contract
symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract
price real NOT NULL, -- price fields for the functionType in contract
timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract
)
CREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )
CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_balances_bitcoin (
block_number bigint NOT NULL, -- Block number containing the transaction
block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction
tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription
wallet_address varchar(42) NOT NULL, -- Address of owner
total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription
amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height
)
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )
CREATE TABLE token_activities_bitcoin (
block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
log_index integer NOT NULL, -- Index of the log within the transaction
type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)
tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription
id varchar(255) NOT NULL, -- Unique identifier of the inscription
amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to "lim"
from_address varchar(62) NOT NULL, -- Address sending the inscription
to_address varchar(62) NOT NULL -- Address receiving the inscription
)
CREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )
| [
{
"role": "user",
"content": "Show me wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount."
},
{
"role": "assistant",
"content": "SELECT eb.wallet_address, tm.symbol, eb.amount FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address WHERE CAST(eb.amount AS decimal) > 1000;"
},
{
"role": "user",
"content": "Can you join this with the token_prices_latest table to include the current price of each token and sort the results by amount in descending order?"
},
{
"role": "assistant",
"content": "SELECT eb.wallet_address, tm.symbol, eb.amount, tpl.price FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address JOIN token_prices_latest tpl ON eb.contract_address = tpl.address WHERE CAST(eb.amount AS decimal) > 1000 ORDER BY CAST(eb.amount AS decimal) DESC;"
}
] |
You are an 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 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(128) NOT NULL, -- e.g., 'Aircraft Mechanic', 'Quality Inspector', 'Assembly Technician'
skill_certifications text, -- comma-separated list or JSON of certifications
hire_date date NOT NULL,
assigned_line_id character varying(64), -- FK to the assembly line the employee is currently assigned to (can be null)
employment_status character varying(50) NOT NULL, -- e.g., 'Active', 'On Leave', 'Terminated'
supervisor_employee_id character varying(64), -- FK to the employee's supervisor (self-reference, nullable)
PRIMARY KEY (employee_id)
)
| [
{
"role": "user",
"content": "What is the current salary of employee with ID 'EMP123'?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information about an employee's salary as it is not included in the data available in the 'employees' table."
}
] |
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.trains ( train_id text, train_number text, model text, manufacturer text, year_manufactured integer, capacity integer, status text, last_maintenance_date date, next_maintenance_date date )
| [
{
"role": "user",
"content": "What is the detailed repair history for train number T5678?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide the detailed repair history for train number T5678 as this information is not available in the current database table. The table only includes basic information such as train ID, model, manufacturer, capacity, status, and maintenance dates. For repair history, you may need to consult a different database or 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 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
// 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 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 schedule details. Key format: schedule:<schedule_id>
// HSET schedule:sched_1122 schedule_id "sched_1122" train_id "train_789" route_id "route_ne_corr" departure_datetime "2024-05-10T08:00:00-04:00" ... status "Scheduled"
// Use Hashes for details. Key format: schedule_stop:<stop_id>
// HSET schedule_stop:stop_sched1122_1 stop_id "stop_sched1122_1" schedule_id "sched_1122" station_id "station_bos" ...
// To find stops for a schedule, use a Sorted Set (score by sequence_order):
// ZADD schedule:sched_1122:stops 1 schedule_stop:stop_sched1122_1
// ZADD schedule:sched_1122:stops 2 schedule_stop:stop_sched1122_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
// Use Hashes for staff details. Key format: staff:<staff_id>
// HSET staff:staff_mno staff_id "staff_mno" first_name "Bob" ... employee_number "E12345" ... is_active 1
// To find staff by employee number (optional index):
// SET staff_employee_number:"E12345" staff:staff_mno
// Use Hashes for maintenance record details. Key format: maintenance_record:<record_id>
// HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed"
// To link records to assets (optional):
// SADD train:train_789:maintenance maintenance_record:maint_rec_001
// SADD platform:plat_123:maintenance maintenance_record:maint_rec_002
| [
{
"role": "user",
"content": "Can you provide the total number of cars associated with a specific train with train_id 'train_789'?"
},
{
"role": "assistant",
"content": "SCARD train:train_789:cars"
}
] |
You are an expert in writing database language. You 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.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.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.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 )
| [
{
"role": "user",
"content": "How many documents of each type exist in the system? Show the document type and the count."
},
{
"role": "assistant",
"content": "SELECT document_type, COUNT(*) AS document_count\nFROM legal_services.documents\ngroup BY document_type;"
}
] |
You are an expert in writing database language. You 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
// 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 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 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 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 )
| [
{
"role": "user",
"content": "Show me all servers that are currently full, meaning current players equals max players. List the server name, region, and max players."
},
{
"role": "assistant",
"content": "SELECT server_name, region, max_players FROM gaming_technology.servers WHERE current_players = max_players;"
},
{
"role": "user",
"content": "Now, only show the full servers from regions that have at least 5 full servers in total."
},
{
"role": "assistant",
"content": "SELECT server_name, region, max_players FROM gaming_technology.servers WHERE current_players = max_players AND region IN ( SELECT region FROM gaming_technology.servers WHERE current_players = max_players GROUP BY region HAVING COUNT(server_id) >= 5 );"
},
{
"role": "user",
"content": "For those specific full servers in those regions, also include the average max players of ALL servers in that region."
},
{
"role": "assistant",
"content": "SELECT server_name, region, max_players, AVG(max_players) OVER (PARTITION BY region) AS regional_avg_max_players FROM gaming_technology.servers WHERE current_players = max_players AND region IN ( SELECT region FROM gaming_technology.servers WHERE current_players = max_players GROUP BY region HAVING COUNT(server_id) >= 5 );"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 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 total number of likes on posts versus likes on comments across the entire platform."
},
{
"role": "assistant",
"content": "SELECT CASE WHEN post_id IS NOT NULL THEN 'post' ELSE 'comment' END AS like_target, COUNT(*) AS total_likes FROM social_media.likes GROUP BY like_target;"
}
] |
You are an expert in writing database language. You 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.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )
| [
{
"role": "user",
"content": "Show me the number of guests registered in each city. Order the results by city name."
},
{
"role": "assistant",
"content": "SELECT city, COUNT(guest_id) AS guest_count FROM guests GROUP BY city ORDER BY city;"
}
] |
You are an expert in writing database language. You 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. You 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, -- unique identifier for the contract
address character varying(128) NOT NULL, -- address of the deployed contract
abi text NOT NULL, -- application binary interface of the contract
bytecode text NOT NULL, -- bytecode of the contract
deployer_address character varying(128) NOT NULL, -- address of the deployer
deployed_at timestamp NOT NULL, -- time when the contract was deployed
network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed
status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)
PRIMARY KEY (contract_id)
)
CREATE TABLE web3.transactions (
transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction
from_address character varying(128) NOT NULL, -- address of the sender
to_address character varying(128), -- address of the receiver (can be null for contract deployment)
value numeric(38,14) NOT NULL, -- value transferred
gas_used integer NOT NULL, -- amount of gas used by the transaction
gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction
block_number integer NOT NULL, -- block number containing the transaction
timestamp timestamp NOT NULL, -- time when the transaction was mined
input_data text, -- input data of the transaction (can be null)
status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)
nonce integer NOT NULL, -- nonce of the sender at the time of the transaction
PRIMARY KEY (transaction_id)
)
CREATE TABLE web3.tokens (
token_id character varying(64) NOT NULL, -- unique identifier for the token
contract_address character varying(128) NOT NULL, -- address of the token contract
token_name character varying(128) NOT NULL, -- name of the token
token_symbol character varying(32) NOT NULL, -- symbol of the token
decimals integer NOT NULL, -- number of decimals for the token
total_supply numeric(38,14) NOT NULL, -- total supply of the token
PRIMARY KEY (token_id)
)
CREATE TABLE web3.token_transfers (
transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer
token_id character varying(64) NOT NULL, -- identifier of the token being transferred
from_address character varying(128) NOT NULL, -- address of the sender
to_address character varying(128) NOT NULL, -- address of the receiver
value numeric(38,14) NOT NULL, -- amount of tokens transferred
transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer
log_index integer NOT NULL, -- index of the transfer log in the transaction
PRIMARY KEY (transfer_id)
)
| [
{
"role": "user",
"content": "List each transaction ID that includes token transfers, along with the distinct symbols of the tokens transferred in that transaction."
},
{
"role": "assistant",
"content": "SELECT T1.transaction_id, STRING_AGG(DISTINCT T3.token_symbol, ', ') FROM web3.transactions AS T1 JOIN web3.token_transfers AS T2 ON T1.transaction_id = T2.transaction_id JOIN web3.tokens AS T3 ON T2.token_id = T3.token_id GROUP BY T1.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 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 gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )
CREATE TABLE gaming_technology.game_sessions (
session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session
player_id uuid NOT NULL, -- FK linking to the players table
game_id uuid NOT NULL, -- FK linking to the games table
server_id uuid, -- FK linking to the servers table (nullable for single-player)
start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began
end_time timestamp with time zone, -- when the session ended (null if ongoing)
duration_seconds integer, -- calculated duration of the session in seconds
score integer, -- player's score for the session, if applicable
session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)
PRIMARY KEY (session_id)
-- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),
-- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),
-- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)
)
CREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )
CREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )
CREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )
CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )
| [
{
"role": "user",
"content": "Show the total number of game sessions played on each server that is currently 'online'. Include the server name, region, and the count of sessions."
},
{
"role": "assistant",
"content": "SELECT s.server_name, s.region, COUNT(gs.session_id) AS total_sessions FROM gaming_technology.game_sessions gs JOIN gaming_technology.servers s ON gs.server_id = s.server_id WHERE s.status = 'online' AND gs.server_id IS NOT NULL GROUP BY s.server_name, s.region ORDER BY total_sessions 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 healthcare.medical_records (
record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry
patient_id character varying(64) NOT NULL, -- FK to patients table
appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)
doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)
record_date timestamp with time zone NOT NULL, -- date the record/observation was made
chief_complaint text, -- patient's primary reason for visit
present_illness_history text, -- detailed history of the current issue
past_medical_history text, -- relevant past conditions/surgeries
physical_examination_notes text, -- findings from the physical exam
assessment text, -- doctor's assessment/diagnosis summary
treatment_plan text, -- planned course of action
vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (record_id)
)
CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
| [
{
"role": "user",
"content": "Can you provide a list of all medical records created by doctors for patients who are associated with 'PPO' type insurance plans? I need the record ID, patient ID, doctor ID, record date, and insurance plan name."
},
{
"role": "assistant",
"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.patient_id IS NOT NULL -- placeholder JOIN, fix below if you have a patient-insurance mapping table\nWHERE ip.plan_type = 'PPO';"
},
{
"role": "user",
"content": "The SQL seems off because there's no direct mapping between patients and insurance_plans in the schema. Can you adjust the query so that it only lists medical records with the plan details if the doctor creating the record has a contact phone number that matches the plan's contact_phone? Still need the same output columns."
},
{
"role": "assistant",
"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL;"
},
{
"role": "user",
"content": "Actually, please sort the results by record_date in descending order and return only the latest 20 records."
},
{
"role": "assistant",
"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL\nORDER BY mr.record_date DESC\nLIMIT 20;"
}
] |
You are an expert in writing database language. You 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.patient_insurance (
patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link
patient_id character varying(64) NOT NULL, -- FK to patients table
plan_id character varying(64) NOT NULL, -- FK to insurance_plans table
policy_number character varying(100) NOT NULL, -- patient's policy number
group_number character varying(100), -- group number, if applicable
subscriber_name character varying(200), -- name of the primary policy holder
effective_date date NOT NULL, -- date the coverage begins
expiration_date date, -- date the coverage ends (if known)
is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance
PRIMARY KEY (patient_insurance_id),
UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice
)
| [
{
"role": "user",
"content": "Show me all patients who have non-primary insurance plans with expiration dates within the next 60 days, along with their policy numbers and subscriber names."
},
{
"role": "assistant",
"content": "SELECT patient_id, policy_number, subscriber_name FROM healthcare.patient_insurance WHERE is_primary = false AND expiration_date BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL '60 days');"
}
] |
You are an expert in writing database language. You 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.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": "What is the average USD value per address for each narrative across all chains?"
},
{
"role": "assistant",
"content": "SELECT\n narrative,\n AVG(usd_value / NULLIF(address_amount, 0)) AS avg_usd_per_address\nFROM smart_money_token_inflow\nGROUP BY narrative;"
}
] |
You are an expert in writing database language. You 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.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )
| [
{
"role": "user",
"content": "Show me, for each game, the achievement that has been unlocked by the most players. Include the game title, achievement name, and the number of players who unlocked it."
},
{
"role": "assistant",
"content": "WITH RankedAchievements AS ( SELECT pa.achievement_id, COUNT(pa.player_id) AS unlock_count, ROW_NUMBER() OVER(PARTITION BY a.game_id ORDER BY COUNT(pa.player_id) DESC) as rn FROM player_achievements pa JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id GROUP BY pa.achievement_id, a.game_id ) SELECT g.title AS game_title, a.name AS achievement_name, ra.unlock_count FROM RankedAchievements ra JOIN gaming_technology.achievements a ON ra.achievement_id = a.achievement_id JOIN games g ON a.game_id = g.game_id WHERE ra.rn = 1;"
},
{
"role": "user",
"content": "Can you refine this to only show games where the top achievement has been unlocked by at least 50 players?"
}
] |
You are an expert in writing database language. You 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.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": "For each transaction, list the total value transferred and the number of different addresses involved (either as sender or receiver)."
},
{
"role": "assistant",
"content": "SELECT transaction_id, SUM(value) AS total_value_transferred, COUNT(DISTINCT addr) AS num_addresses_involved\nFROM (\n SELECT transaction_id, from_address AS addr, value FROM web3.token_transfers\n UNION ALL\n SELECT transaction_id, to_address AS addr, 0 as value FROM web3.token_transfers\n) t\nGROUP 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 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.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 manufacturing.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(128) NOT NULL, skill_certifications text, hire_date date NOT NULL, assigned_line_id character varying(64), employment_status character varying(50) NOT NULL, supervisor_employee_id character varying(64), PRIMARY KEY (employee_id) )
| [
{
"role": "user",
"content": "What is the performance review score for employee with ID 'EMP456' for the last quarter?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't assist with information about performance review scores as this data is not included in the employees table."
}
] |
You are an expert in writing database language. You 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 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.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )
CREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )
CREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )
CREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )
CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
CREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )
| [
{
"role": "user",
"content": "For each patient, show the total number of diagnoses they have received, along with their patient ID and the ID of their latest diagnosis. Join with the diagnoses table."
},
{
"role": "assistant",
"content": "SELECT patient_id, COUNT(diagnosis_id) AS diagnosis_count, MAX(diagnosis_id) AS latest_diagnosis_id\nFROM healthcare.diagnoses\nGROUP BY patient_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.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 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 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.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;"
}
] |
You are an expert in writing database language. You 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 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. You 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.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )
CREATE TABLE web3.transactions ( transaction_id text PRIMARY KEY, from_address text, to_address text, value numeric, gas_used int, gas_price numeric, block_number int, timestamp timestamp, input_data text, status text, nonce int )
CREATE TABLE web3.token_transfers (
transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer
token_id character varying(64) NOT NULL, -- identifier of the token being transferred
from_address character varying(128) NOT NULL, -- address of the sender
to_address character varying(128) NOT NULL, -- address of the receiver
value numeric(38,14) NOT NULL, -- amount of tokens transferred
transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer
log_index integer NOT NULL, -- index of the transfer log in the transaction
PRIMARY KEY (transfer_id)
)
CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
| [
{
"role": "user",
"content": "Find all token transfers where the value is greater than 5000, including the token_id and transaction details like from_address and gas_used, sorted by value in descending order."
},
{
"role": "assistant",
"content": "SELECT tt.token_id, tt.value, t.from_address, t.to_address, t.gas_used, t.block_number, t.timestamp FROM web3.token_transfers tt JOIN web3.transactions t ON tt.transaction_id = t.transaction_id WHERE tt.value > 5000 ORDER BY tt.value 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 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. You 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 trading_platform.wallets (
wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet
user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet
address character varying(128) NOT NULL, -- address of the wallet
private_key text NOT NULL, -- private key of the wallet
created_at timestamp NOT NULL, -- time when the wallet was created
PRIMARY KEY (wallet_id)
)
CREATE TABLE trading_platform.orders (
order_id character varying(64) NOT NULL, -- unique identifier for the order
user_id character varying(64) NOT NULL, -- identifier of the user placing the order
wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order
asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)
quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order
price numeric(38,14) NOT NULL, -- price per unit of the asset
status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)
created_at timestamp NOT NULL, -- time when the order was created
PRIMARY KEY (order_id)
)
CREATE TABLE trading_platform.assets (
asset_id character varying(64) NOT NULL, -- unique identifier for the asset
name character varying(128) NOT NULL, -- name of the asset
symbol character varying(32) NOT NULL, -- symbol of the asset
type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)
PRIMARY KEY (asset_id)
)
CREATE TABLE trading_platform.utxos (
utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO
transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO
output_index integer NOT NULL, -- index of the output in the transaction
address character varying(128) NOT NULL, -- address that can spend the UTXO
amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO
spent boolean NOT NULL, -- whether the UTXO has been spent
PRIMARY KEY (utxo_id)
)
CREATE TABLE trading_platform.dapps (
dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp
name character varying(128) NOT NULL, -- name of the DApp
description text NOT NULL, -- description of the DApp
url character varying(256) NOT NULL, -- URL of the DApp
PRIMARY KEY (dapp_id)
)
CREATE TABLE trading_platform.peers (
peer_id character varying(64) NOT NULL, -- unique identifier for the peer
ip_address character varying(15) NOT NULL, -- IP address of the peer
port integer NOT NULL, -- port number of the peer
last_seen timestamp NOT NULL, -- last time the peer was active
PRIMARY KEY (peer_id)
)
CREATE TABLE trading_platform.metadata (
metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata
asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
key character varying(128) NOT NULL, -- key of the metadata
value text NOT NULL, -- value of the metadata
PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.kyc_audit (
kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit
user_id character varying(64) NOT NULL, -- identifier of the user being audited
status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)
reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed
PRIMARY KEY (kyc_audit_id)
)
CREATE TABLE trading_platform.notifications (
notification_id character varying(64) NOT NULL, -- unique identifier for the notification
user_id character varying(64) NOT NULL, -- identifier of the user receiving the notification
message text NOT NULL, -- message of the notification
sent_at timestamp NOT NULL, -- time when the notification was sent
read_at timestamp, -- time when the notification was read
PRIMARY KEY (notification_id)
)
| [
{
"role": "user",
"content": "For each asset, calculate the total quantity and average price of orders that have status 'filled'."
},
{
"role": "assistant",
"content": "SELECT o.asset_id,\n SUM(o.quantity) AS total_quantity,\n AVG(o.price) AS average_price\nFROM trading_platform.orders o\nWHERE o.status = 'filled'\nGROUP BY o.asset_id;"
}
] |
You are an expert in writing database language. You 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 a expert in writing database language. You 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 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 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.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 )
| [
{
"role": "user",
"content": "For each peer port, count how many peers have used that port."
},
{
"role": "assistant",
"content": "SELECT port,\n COUNT(*) AS peer_count\nFROM trading_platform.peers\nGROUP BY port;"
}
] |
You are an expert in writing database language. You 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 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 web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )
| [
{
"role": "user",
"content": "For each event, display its event_id, the event_id of the previous event in the same transaction (if any), and the log_index of both events."
},
{
"role": "assistant",
"content": "SELECT curr.event_id AS current_event_id,\n prev.event_id AS previous_event_id,\n curr.log_index AS current_log_index,\n prev.log_index AS previous_log_index,\n curr.transaction_id\nFROM web3.events curr\nLEFT JOIN web3.events prev\n ON curr.transaction_id = prev.transaction_id\n AND curr.log_index = prev.log_index + 1;"
}
] |
You are an expert in writing database language. You 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 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 current address of the employee with ID 'EMP234'?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide the current address of an employee as this information is not stored in the 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 government_services.citizens (
citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen
national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
first_name character varying(100) NOT NULL,
last_name character varying(100) NOT NULL,
date_of_birth date NOT NULL,
gender character varying(20),
primary_address text NOT NULL, -- full primary residential address
contact_email character varying(128) UNIQUE,
contact_phone character varying(32),
registration_date timestamp NOT NULL, -- when the citizen profile was created
is_verified boolean DEFAULT false, -- whether identity has been officially verified
PRIMARY KEY (citizen_id)
)
CREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )
CREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )
CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )
CREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp )
CREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )
CREATE TABLE government_services.service_locations (
location_id character varying(64) NOT NULL, -- unique identifier for the physical location
agency_id character varying(64) NOT NULL, -- FK to agencies table
location_name character varying(200), -- e.g., Downtown DMV Office
address text NOT NULL,
city character varying(100),
state character varying(50),
postal_code character varying(20),
latitude numeric(9, 6),
longitude numeric(9, 6),
operating_hours text, -- description of opening times
contact_phone character varying(32),
is_accessible boolean, -- accessibility information (e.g., wheelchair access)
PRIMARY KEY (location_id)
)
CREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )
| [
{
"role": "user",
"content": "Show each service's name along with the total number of appointments scheduled and the number of unique locations these appointments are scheduled at."
},
{
"role": "assistant",
"content": "SELECT s.service_name, COUNT(a.application_id) AS appointment_count, COUNT(DISTINCT ap.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.appointments ap ON a.application_id = ap.application_id\nGROUP BY s.service_name;"
},
{
"role": "user",
"content": "I got an error: relation 'appointments' does not exist."
},
{
"role": "assistant",
"content": "-- The appointments table is not present in the provided schema. If you want to count by another join, perhaps by documents or payments, please specify.\n-- Alternatively, do you want appointment information replaced with application submissions per service and their associated location from service_locations?\nSELECT s.service_name, COUNT(a.application_id) AS application_count, COUNT(DISTINCT sl.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.service_locations sl ON s.agency_id = sl.agency_id\nGROUP BY s.service_name;"
},
{
"role": "user",
"content": "Show only those services where application_count is greater than 50."
},
{
"role": "assistant",
"content": "SELECT s.service_name, COUNT(a.application_id) AS application_count, COUNT(DISTINCT sl.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.service_locations sl ON s.agency_id = sl.agency_id\nGROUP BY s.service_name\nHAVING COUNT(a.application_id) > 50;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE blockchain.transactions ( transaction_id text, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text )
CREATE TABLE blockchain.smart_contracts ( contract_id text, creator_address text, code text, timestamp timestamp )
| [
{
"role": "user",
"content": "Find all smart contracts deployed in 2022 that have never received any transactions."
},
{
"role": "assistant",
"content": "SELECT sc.contract_id, sc.creator_address, sc.timestamp AS deployment_time\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nWHERE sc.timestamp >= '2022-01-01' AND sc.timestamp < '2023-01-01'\n AND t.transaction_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.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 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 web3.contracts (
contract_id character varying(64) NOT NULL, -- unique identifier for the contract
address character varying(128) NOT NULL, -- address of the deployed contract
abi text NOT NULL, -- application binary interface of the contract
bytecode text NOT NULL, -- bytecode of the contract
deployer_address character varying(128) NOT NULL, -- address of the deployer
deployed_at timestamp NOT NULL, -- time when the contract was deployed
network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed
status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)
PRIMARY KEY (contract_id)
)
CREATE TABLE web3.transactions (
transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction
from_address character varying(128) NOT NULL, -- address of the sender
to_address character varying(128), -- address of the receiver (can be null for contract deployment)
value numeric(38,14) NOT NULL, -- value transferred
gas_used integer NOT NULL, -- amount of gas used by the transaction
gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction
block_number integer NOT NULL, -- block number containing the transaction
timestamp timestamp NOT NULL, -- time when the transaction was mined
input_data text, -- input data of the transaction (can be null)
status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)
nonce integer NOT NULL, -- nonce of the sender at the time of the transaction
PRIMARY KEY (transaction_id)
)
CREATE TABLE web3.wallets (
wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet
user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet
address character varying(128) NOT NULL, -- address of the wallet
private_key text NOT NULL, -- private key of the wallet
created_at timestamp NOT NULL, -- time when the wallet was created
PRIMARY KEY (wallet_id)
)
| [
{
"role": "user",
"content": "Show each contract address and the count of successful transactions sent to that contract."
},
{
"role": "assistant",
"content": "SELECT c.address, COUNT(t.transaction_id) AS success_tx_count FROM web3.contracts c JOIN web3.transactions t ON t.to_address = c.address AND t.status = 'success' GROUP BY c.address;"
}
] |
You are an expert in writing database language. You 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 transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )
| [
{
"role": "user",
"content": "List each driver along with the driver_id of the driver who was hired immediately after them."
},
{
"role": "assistant",
"content": "SELECT d1.driver_id AS current_driver_id, d2.driver_id AS next_driver_id FROM transportation.drivers d1 LEFT JOIN transportation.drivers d2 ON d2.hire_date = (SELECT MIN(hire_date) FROM transportation.drivers WHERE hire_date > d1.hire_date);"
}
] |
You are an expert in writing database language. You 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 )
| [
{
"role": "user",
"content": "Can you narrow this down to only show cases where the case type is 'Criminal'?"
},
{
"role": "assistant",
"content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE lead_lawyer_id = 'lawyer_abc' AND status = 'Open' AND case_type = 'Criminal';"
}
] |
You are an expert in writing database language. You 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.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )
CREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )
CREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )
CREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )
CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )
CREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )
CREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )
| [
{
"role": "user",
"content": "List games that have servers deployed in more than one geographical region. Show the game title and the count of regions."
},
{
"role": "assistant",
"content": "SELECT g.title, count(DISTINCT s.region) AS region_count FROM games AS g JOIN servers AS s ON g.game_id = s.game_id GROUP BY g.game_id, g.title HAVING count(DISTINCT s.region) > 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.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.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 )
| [
{
"role": "user",
"content": "What are the top 5 product types by average base premium, showing the product_type and average base_premium, ordered by average base_premium descending?"
},
{
"role": "assistant",
"content": "SELECT product_type, AVG(base_premium) AS avg_premium FROM insurance.insurance_products GROUP BY product_type ORDER BY avg_premium DESC LIMIT 5;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )
CREATE TABLE token_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 character varying(512) NOT NULL, -- the id of narrative",
"top_3_coins text, -- the top 3 tokens in the narrative",
"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative",
"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative",
"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative",
"market_cap double precision, -- the market cap of the narrative",
"volume_24h double precision, -- the trade volume of the narrative",
"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative",
"token_num bigint, -- total token number in the narrative",
",PRIMARY KEY (narrative));"
"CREATE TABLE cex_token_balance (",
"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp",
"chain character varying(128) NOT NULL, -- the chain that the token resides",
"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX",
"exchange character varying(512) NOT NULL, -- a centralized exchange name",
"token_address character varying(128) NOT NULL, -- token contract address",
"token_symbol character varying(512), --token symbol",
"balance numeric(38,10), -- token balance",
"usd_value numeric(38,14), -- value of the token held in USD",
"price double precision, --price of the token in USD",
",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));"
CREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )
CREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )
CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )
| [
{
"role": "user",
"content": "What are the top 5 tokens by 7-day price change percentage? Show token_symbol, token_name, narrative, and chain, ordered by price_change_percentage_7d descending."
},
{
"role": "assistant",
"content": "```sql\nSELECT\n token_symbol,\n token_name,\n narrative,\n chain\nFROM token_basic_info\nORDER BY price_change_percentage_7d DESC\nLIMIT 5;\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 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.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.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": "Which users have received both a comment notification and a like notification? List the recipient_user_id and the total number of such users."
},
{
"role": "assistant",
"content": "SELECT COUNT(DISTINCT recipient_user_id) AS user_count\nFROM (\n SELECT recipient_user_id\n FROM social_media.notifications\n WHERE notification_type = 'comment'\n INTERSECT\n SELECT recipient_user_id\n FROM social_media.notifications\n WHERE notification_type = 'like'\n) AS users_with_both;"
}
] |
You are an expert in writing database language. You 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.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 )
| [
{
"role": "user",
"content": "Show a list of all DApps together with the total number of unique assets linked to each via the metadata table."
},
{
"role": "assistant",
"content": "SELECT d.dapp_id, d.name, d.url, COUNT(DISTINCT m.asset_id) AS unique_asset_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON m.asset_id IS NOT NULL\nGROUP BY d.dapp_id, d.name, d.url;"
}
] |
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 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 PRIMARY KEY, 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 total number of vacation days taken by employee with ID 'EMP101' in the past year?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the vacation days taken by an employee as this data is not stored in the current table structure."
}
] |
You are an expert in writing database language. You 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 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
// Use Hashes for maintenance record details. Key format: maintenance_record:<record_id>
// HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed"
// To link records to assets (optional):
// SADD train:train_789:maintenance maintenance_record:maint_rec_001
// SADD platform:plat_123:maintenance maintenance_record:maint_rec_002
| [
{
"role": "user",
"content": "特定の列車ID 'train_789' に関連するすべてのメンテナンス記録の詳細を取得するのを手伝っていただけますか?"
},
{
"role": "assistant",
"content": "SMEMBERS train:train_789:maintenance\nHGETALL maintenance_record:<record_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 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) )
| [
{
"role": "user",
"content": "Which rooms on the 4th floor are non-smoking, along with their property IDs and type IDs?"
},
{
"role": "assistant",
"content": "SELECT room_id, property_id, room_number, room_type_id FROM hospitality_technology.rooms WHERE floor = 4 AND is_smoking = FALSE;"
}
] |
You are an expert in writing database language. You 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.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address text NOT NULL, city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status character varying(32) NOT NULL, risk_profile character varying(50), PRIMARY KEY (customer_id) )
CREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )
CREATE TABLE financial_services.securities ( security_id character varying(64) NOT NULL, ticker_symbol character varying(20) NOT NULL UNIQUE, isin_code character varying(12) UNIQUE, cusip_code character varying(9) UNIQUE, security_name text NOT NULL, security_type character varying(50) NOT NULL, exchange character varying(50), currency character varying(3) NOT NULL, issuer_name character varying(255), sector character varying(100), last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (security_id) )
CREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )
CREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )
CREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )
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": "For each security, show the average daily volume from market data and the total quantity traded across all trades."
},
{
"role": "assistant",
"content": "WITH MarketDataAgg AS ( SELECT security_id, AVG(volume) AS avg_daily_volume FROM financial_services.market_data GROUP BY security_id ), TradesAgg AS ( SELECT security_id, SUM(quantity) AS total_quantity_traded FROM financial_services.trades GROUP BY security_id ) SELECT T1.ticker_symbol, T1.security_name, T2.avg_daily_volume, T3.total_quantity_traded FROM financial_services.securities AS T1 LEFT JOIN MarketDataAgg AS T2 ON T1.security_id = T2.security_id LEFT JOIN TradesAgg AS T3 ON T1.security_id = T3.security_id WHERE T2.avg_daily_volume IS NOT NULL OR T3.total_quantity_traded IS NOT NULL;"
},
{
"role": "user",
"content": "Only include securities where the average daily volume is above 500000 and the total quantity traded is above 10000."
}
] |
You are an expert in writing database language. You 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": "List the name and symbol for all assets that do not have a corresponding entry with the key 'website' in the metadata table."
},
{
"role": "assistant",
"content": "SELECT T1.name , T1.symbol FROM trading_platform.assets AS T1 LEFT JOIN trading_platform.metadata AS T2 ON T1.asset_id = T2.asset_id AND T2.key = 'website' WHERE T2.metadata_id IS NULL"
}
] |
You are an expert in writing database language. You 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 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.text, first_name.text, last_name.text, role.text, primary_station_id.text, employee_number.text, hire_date.date, contact_email.text, contact_phone.text, is_active.boolean )
| [
{
"role": "user",
"content": "What is the current job satisfaction level or feedback from staff members working at a specific train station?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on job satisfaction levels or feedback from staff members as this data is not included in the staff table."
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE blockchain.smart_contracts ( contract_id.text, creator_address.text, code.text, timestamp.timestamp )
| [
{
"role": "user",
"content": "Find all smart contracts where the contract code contains the keyword 'proxy'."
},
{
"role": "assistant",
"content": "SELECT contract_id, creator_address, timestamp FROM blockchain.smart_contracts WHERE code LIKE '%proxy%';"
},
{
"role": "user",
"content": "For these 'proxy' contracts, can you also include the total number of contracts deployed by each creator?"
},
{
"role": "assistant",
"content": "SELECT sc.contract_id, sc.creator_address, sc.timestamp, creator_counts.total_contracts FROM blockchain.smart_contracts sc JOIN ( SELECT creator_address, COUNT(*) as total_contracts FROM blockchain.smart_contracts GROUP BY creator_address ) creator_counts ON sc.creator_address = creator_counts.creator_address WHERE sc.code LIKE '%proxy%';"
}
] |
You are an expert in writing database language. You 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.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )
| [
{
"role": "user",
"content": "Show the customer_id and pairs of payment_ids for any customers who have overlapping payment periods."
},
{
"role": "assistant",
"content": "SELECT p1.customer_id,\n p1.payment_id AS payment1_id,\n p2.payment_id AS payment2_id\nFROM insurance.premium_payments p1\nJOIN insurance.premium_payments p2\n ON p1.customer_id = p2.customer_id\n AND p1.payment_id < p2.payment_id\n AND p1.payment_period_start <= p2.payment_period_end\n AND p1.payment_period_end >= p2.payment_period_start;"
}
] |
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, asset_id character varying(64) NOT NULL, asset_type character varying(32) NOT NULL, maintenance_type character varying(128) NOT NULL, staff_id character varying(64), start_datetime timestamp NOT NULL, end_datetime timestamp, description text NOT NULL, cost numeric(12, 2), status character varying(32) NOT NULL DEFAULT 'Completed', PRIMARY KEY (record_id), FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id) )
| [
{
"role": "user",
"content": "What is the reason behind the cost variation for maintenance of asset_id 'ASSET456' over the past year?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the reasons behind cost variations for maintenance. The data in the maintenance_records table includes only the cost amount and other basic details of each maintenance record, but it does not contain explanations or factors influencing cost changes."
}
] |
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 total revenue generated by ticket sales at the station with ID 'ST101' for the past month?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the revenue generated by ticket sales as this data is not available in the current database table. The table only contains details about station information such as name, location, and platform count. If you have another question or need assistance with something else related to the station data, I'm happy to help."
}
] |
You are an expert in writing database language. You 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 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
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 fetch the inventory records for components stored in a specific warehouse, along with their expiry dates?"
},
{
"role": "assistant",
"content": "HGETALL inv:<inventory_record_id>\nZRANGE component_expiry:<component_id> 0 -1 WITHSCORES"
},
{
"role": "user",
"content": "Can you filter this to show only records for a specific component ID?"
},
{
"role": "assistant",
"content": "HGETALL inv:<inventory_record_id>\nZRANGE component_expiry:<component_id> 0 -1 WITHSCORES"
},
{
"role": "user",
"content": "What if I want to exclude records with quantities below a certain threshold, like 100?"
},
{
"role": "assistant",
"content": "HGETALL inv:<inventory_record_id>\nZRANGE component_expiry:<component_id> 0 -1 WITHSCORES\n# Note: Filtering by quantity would require additional scripting or client-side processing as Redis does not support direct filtering on hash field values."
},
{
"role": "user",
"content": "Can you also sort the results by expiry date in descending order?"
},
{
"role": "assistant",
"content": "HGETALL inv:<inventory_record_id>\nZREVRANGE component_expiry:<component_id> 0 -1 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 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 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. You 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 character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )
CREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )
CREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )
| [
{
"role": "user",
"content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 6 months, along with their narrative information if available."
},
{
"role": "assistant",
"content": "SELECT pfr.project_name, pfr.rounds_name, pfr.valuation, pfr.investment_date, ni.narrative, ni.trend_rank\nFROM project_fundraising_record pfr\nLEFT JOIN narrative_info ni ON pfr.project_name = ni.narrative\nWHERE pfr.investment_date >= date_sub(now(), interval 6 month)\nORDER BY pfr.valuation DESC\nLIMIT 5;"
},
{
"role": "user",
"content": "Can you filter these results to only include projects with valuation over $50 million and add their 24-hour trading volume from the narrative?"
},
{
"role": "assistant",
"content": "SELECT pfr.project_name, pfr.rounds_name, pfr.valuation, ni.volume_24h\nFROM project_fundraising_record pfr\nLEFT JOIN narrative_info ni ON pfr.project_name = ni.narrative\nWHERE pfr.investment_date >= date_sub(now(), interval 6 month)\nAND pfr.valuation > 50000000\nORDER BY pfr.valuation DESC\nLIMIT 5;"
}
] |
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )
| [
{
"role": "user",
"content": "What is the average number of days by which paid invoices were paid late? Calculate the average of (payment_date - due_date) for invoices with status 'Paid'."
},
{
"role": "assistant",
"content": "SELECT AVG((payment_date::date - due_date)) AS average_late_days\nFROM legal_services.invoices\nWHERE status = 'Paid';"
}
] |
You are an expert in writing database language. You 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": "List the token symbol, token name, and contract address for all tokens that have no recorded transfers in the token_transfers table."
},
{
"role": "assistant",
"content": "SELECT T.token_symbol, T.token_name, T.contract_address FROM web3.tokens AS T LEFT JOIN token_transfers AS TT ON T.token_id = TT.token_id WHERE TT.transfer_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 healthcare.medications (
medication_id character varying(64) NOT NULL, -- unique identifier for the medication type
medication_name character varying(255) NOT NULL, -- common or brand name
generic_name character varying(255), -- generic chemical name
manufacturer character varying(100), -- drug manufacturer
ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)
description text, -- description of the medication
PRIMARY KEY (medication_id)
)
| [
{
"role": "user",
"content": "List the names of manufacturers that produce at least one medication with a description and at least one medication without a description."
},
{
"role": "assistant",
"content": "SELECT DISTINCT manufacturer FROM healthcare.medications m1 WHERE manufacturer IS NOT NULL AND EXISTS (SELECT 1 FROM healthcare.medications m2 WHERE m2.manufacturer = m1.manufacturer AND m2.description IS NOT NULL) AND EXISTS (SELECT 1 FROM healthcare.medications m3 WHERE m3.manufacturer = m1.manufacturer AND m3.description 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.stations (
station_id character varying(64) NOT NULL, -- Unique identifier for the station
station_name character varying(128) NOT NULL, -- Name of the station
city character varying(100) NOT NULL, -- City where the station is located
state_province character varying(100), -- State or province
country_code character varying(3) NOT NULL, -- ISO country code
address text, -- Full address of the station
timezone character varying(64) NOT NULL, -- Timezone ID (e.g., 'America/New_York')
number_of_platforms integer NOT NULL DEFAULT 0, -- Total number of platforms
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the station record was created
last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the station record was last updated
PRIMARY KEY (station_id)
)
| [
{
"role": "user",
"content": "What is the current number of passengers at station with ID 'ST123' right now?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the current number of passengers at a station. The data I have access to only includes static details about stations such as their name, location, and number of platforms, not real-time passenger counts."
}
] |
You are an expert in writing database language. You 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, username.text, email.text, password_hash.text, created_at.timestamp )
CREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )
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, name text, description text, url text )
CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )
CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id.text, 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, user_id text, message text, sent_at timestamp, read_at timestamp )
| [
{
"role": "user",
"content": "List all distinct asset types from the assets table."
},
{
"role": "assistant",
"content": "SELECT DISTINCT type\nFROM trading_platform.assets;"
}
] |
You are an expert in writing database language. You 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 route numbers connect locations with a distance less than 80 km and more than 5 words in their description? Include the route type in the results."
},
{
"role": "assistant",
"content": "SELECT route_number, type FROM transportation.routes WHERE distance_km < 80 AND array_length(regexp_split_to_array(description, '\\s+'), 1) > 5;"
}
] |
You are an expert in writing database language. You 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 character varying(64) NOT NULL, -- unique identifier for the driver
employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number
first_name character varying(128) NOT NULL, -- driver's first name
last_name character varying(128) NOT NULL, -- driver's last name
license_number character varying(64) NOT NULL UNIQUE, -- driving license number
license_expiry_date date NOT NULL, -- expiry date of the license
contact_number character varying(32), -- phone number
email character varying(128) UNIQUE, -- email address
hire_date date NOT NULL, -- date the driver was hired
status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated
PRIMARY KEY (driver_id)
)
CREATE TABLE transportation.routes (
route_id character varying(64) NOT NULL, -- unique identifier for the route
route_number character varying(32) NOT NULL UNIQUE, -- public-facing route number/name
description text, -- description of the route
origin_location_id character varying(64) NOT NULL, -- identifier of the starting location
destination_location_id character varying(64) NOT NULL, -- identifier of the ending location
distance_km numeric(10, 2), -- estimated distance in kilometers
estimated_duration_minutes integer, -- estimated travel time in minutes
type character varying(32) NOT NULL, -- e.g., City Bus, Intercity Train, Cargo Delivery
PRIMARY KEY (route_id)
)
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 character varying(64) NOT NULL, -- unique identifier for the location
name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)
type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address
address_line1 character varying(255), -- street address
city character varying(128), -- city name
state_province character varying(128), -- state or province
postal_code character varying(32), -- postal code
country character varying(64) NOT NULL, -- country name
latitude numeric(9, 6), -- geographic latitude
longitude numeric(9, 6), -- geographic longitude
timezone character varying(64), -- IANA timezone name (e.g., America/New_York)
PRIMARY KEY (location_id)
)
CREATE TABLE transportation.maintenance_logs (
log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record
vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced
service_date date NOT NULL, -- date the service was performed
odometer_reading integer, -- vehicle mileage at time of service
service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)
description text NOT NULL, -- detailed description of work done
cost numeric(10, 2), -- cost of the service
mechanic_name character varying(128), -- name or ID of the mechanic/shop
next_service_due_date date, -- recommended date for next service
PRIMARY KEY (log_id)
)
CREATE TABLE transportation.fuel_logs (
fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry
vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled
trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred
log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred
fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)
quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)
unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)
cost_per_unit numeric(8, 4), -- price per unit of fuel
total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase
odometer_reading integer, -- vehicle mileage at time of fueling
location_id character varying(64), -- identifier of the fueling station/location
PRIMARY KEY (fuel_log_id)
)
CREATE TABLE transportation.passengers (
passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger
first_name character varying(128) NOT NULL, -- passenger's first name
last_name character varying(128) NOT NULL, -- passenger's last name
email character varying(128) UNIQUE, -- email address
phone_number character varying(32) UNIQUE, -- phone number
date_of_birth date, -- passenger's date of birth
loyalty_program_id character varying(64), -- identifier for loyalty program membership
created_at timestamp with time zone NOT NULL, -- time when the passenger record was created
PRIMARY KEY (passenger_id)
)
CREATE TABLE transportation.bookings (
booking_id character varying(64) NOT NULL, -- unique identifier for the booking
passenger_id character varying(64) NOT NULL, -- identifier of the passenger making the booking
trip_id character varying(64) NOT NULL, -- identifier of the trip being booked
seat_number character varying(16), -- assigned seat number (if applicable)
booking_time timestamp with time zone NOT NULL, -- time when the booking was made
status character varying(32) NOT NULL, -- e.g., Confirmed, Cancelled, Pending Payment
fare numeric(10, 2) NOT NULL, -- price paid for the booking
payment_transaction_id character varying(128), -- reference to the payment transaction
special_requests text, -- any special requests from the passenger
PRIMARY KEY (booking_id)
)
| [
{
"role": "user",
"content": "Show each maintenance log with the vehicle ID, make, model, service date, and the cost, including the city where the maintenance was performed."
},
{
"role": "assistant",
"content": "SELECT ml.log_id, ml.vehicle_id, v.make, v.model, ml.service_date, ml.cost, l.city AS maintenance_city\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nLEFT JOIN transportation.locations l ON v.depot_id = l.location_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.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 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 fuel consumption rates per hour for the Boeing 747-8 model?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the fuel consumption rates for the Boeing 747-8 model as this data is not included in the aircraft_models table. The table contains details such as model name, manufacturer, passenger capacity, and other specifications, but fuel consumption data is not available. If you have another question or need assistance with something else related to the 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 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 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 character varying(64) NOT NULL, station_id character varying(64) NOT NULL, platform_number character varying(10) NOT NULL, track_number character varying(10), status character varying(32) NOT NULL DEFAULT 'Operational', length_meters numeric(8,2), accessible boolean NOT NULL DEFAULT false, PRIMARY KEY (platform_id), FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id) )
| [
{
"role": "user",
"content": "What is the current number of passengers waiting at platform 2B at station ABC?"
},
{
"role": "assistant",
"content": "I'm sorry, but I can't provide information on the current number of passengers at a specific platform. The data in the platforms table only includes details like platform number, track number, status, length, and accessibility. For real-time passenger counts, you may need to refer to station monitoring systems or staff 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 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 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 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 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 social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )
| [
{
"role": "user",
"content": "List usernames and the length of their 'bio' field for users whose 'is_verified' status is true."
},
{
"role": "assistant",
"content": "SELECT username, LENGTH(bio) AS bio_length FROM social_media.users WHERE is_verified IS TRUE;"
}
] |
You are an 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 healthcare.doctors ( doctor_id.text, first_name.text, last_name.text, specialty.text, license_number.text, phone_number.text, email.text, hospital_affiliation_id.text, created_at.timestamp, updated_at.timestamp )
CREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )
CREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )
CREATE TABLE healthcare.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": "List all chronic diagnoses made by Cardiology specialists in the last year, including the patient ID, diagnosis description, and doctor's full name."
},
{
"role": "assistant",
"content": "SELECT dg.patient_id, dg.description, d.first_name || ' ' || d.last_name AS doctor_name FROM healthcare.diagnoses dg JOIN healthcare.doctors d ON dg.doctor_id = d.doctor_id WHERE d.specialty = 'Cardiology' AND dg.is_chronic = TRUE AND dg.diagnosis_date >= CURRENT_DATE - INTERVAL '1 year';"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.