System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )
CREATE TABLE erc1155_approval_for_all (
    block_number bigint NOT NULL, -- Block 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, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )
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 varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )
CREATE TABLE sui_coins_metadata (
    object_id varchar NOT NULL, -- object id of the coin metadata object
    coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN
    status varchar NOT NULL, -- coin status, eg. exists, deleted
    decimals bigint NOT NULL, -- decimals of the coin
    description varchar NOT NULL, -- description of the coin
    icon_url varchar NOT NULL, -- icon url of the coin
    symbol varchar NOT NULL, -- symbol of the coin
    name varchar NOT NULL  -- name of the coin
)
CREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )
CREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )
CREATE TABLE token_balances (
    block_number bigint NOT NULL, -- Block number containing the transaction
    block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction
    tick varchar NOT NULL, -- Token tick
    wallet_address varchar(42) NOT NULL, -- Address of owner
    total_supply decimal(38,0) NOT NULL, -- Max supply
    amount decimal(38,0) NOT NULL  -- The balance of wallet balance at the corresponding block height
)
CREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )
CREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin (
    block_number bigint 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, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_balances_avalanche (
    block_number bigint NOT NULL, -- Block number containing the transaction
    block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction
    tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription
    wallet_address varchar(42) NOT NULL, -- Address of owner
    total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription
    amount decimal(38,0) NOT NULL  -- The balance of wallet balance at the corresponding block height
)
CREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )

[User] List all active SUI coins with their symbol, name, and total balance across all owners.

[Assistant]
SELECT scm.coin_type, scm.symbol, scm.name, SUM(CAST(sc.balance AS DECIMAL)) AS total_balance
FROM sui_coins_metadata scm
JOIN sui_coins sc ON sc.coin_type = scm.coin_type
WHERE sc.status = 'active' AND scm.status = 'exists'
GROUP BY scm.coin_type, scm.symbol, scm.name;

[User] Filter coins with description containing 'staking' and sort by total_balance descending.

[Assistant]
SELECT sub.coin_type, sub.symbol, sub.name, sub.total_balance
FROM (
  SELECT scm.coin_type, scm.symbol, scm.name, SUM(CAST(sc.balance AS DECIMAL)) AS total_balance
  FROM sui_coins_metadata scm
  JOIN sui_coins sc ON sc.coin_type = scm.coin_type
  WHERE sc.status = 'active' AND scm.status = 'exists' AND LOWER(scm.description) LIKE '%staking%'
  GROUP BY scm.coin_type, scm.symbol, scm.name
) sub
ORDER BY sub.total_balance DESC;

[User] Limit the result to the top 3 coins.

[Assistant]
SELECT sub.coin_type, sub.symbol, sub.name, sub.total_balance
FROM (
  SELECT scm.coin_type, scm.symbol, scm.name, SUM(CAST(sc.balance AS DECIMAL)) AS total_balance
  FROM sui_coins_metadata scm
  JOIN sui_coins sc ON sc.coin_type = scm.coin_type
  WHERE sc.status = 'active' AND scm.status = 'exists' AND LOWER(scm.description) LIKE '%staking%'
  GROUP BY scm.coin_type, scm.symbol, scm.name
) sub
ORDER BY sub.total_balance DESC
LIMIT 3;


System:
You are very professional for database language writing. You 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.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )

[User] List the first and last names of guests residing in California who are loyalty members.

[Assistant] SELECT first_name, last_name FROM hospitality_technology.guests WHERE state_province = 'California' AND loyalty_member_id IS NOT NULL;

[User] Now, only include those who have communication consent enabled and sort by last name.

[Assistant] SELECT first_name, last_name FROM hospitality_technology.guests WHERE state_province = 'California' AND loyalty_member_id IS NOT NULL AND communication_consent = TRUE ORDER BY last_name;


System:
You are very professional for database language writing. You 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 PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )

[User] Find all pairs of origin and destination cities, along with their route_number and distance, where the estimated duration is less than 90 minutes.

[Assistant] SELECT route_number, origin_location_id, destination_location_id, distance_km FROM transportation.routes WHERE estimated_duration_minutes < 90;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )
CREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE sui_coins_metadata (
    object_id varchar NOT NULL, -- object id of the coin metadata object
    coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN
    status varchar NOT NULL, -- coin status, eg. exists, deleted
    decimals bigint NOT NULL, -- decimals of the coin
    description varchar NOT NULL, -- description of the coin
    icon_url varchar NOT NULL, -- icon url of the coin
    symbol varchar NOT NULL, -- symbol of the coin
    name varchar NOT NULL  -- name of the coin
)
CREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )
CREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )
CREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )
CREATE TABLE token_info (
    block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
    block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
    tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
    tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
    tick varchar NOT NULL, -- Token tick
    max_supply decimal(38,0) NOT NULL, -- Max supply
    lim decimal(38,0) NOT NULL, -- Limit of each mint
    wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint
    dec integer NOT NULL, -- Decimal for minimum divie
    creator varchar(42) NOT NULL  -- Address originating the inscription (matches from_address in transactions table)
)
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash 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, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )
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 )

[User] Show ERC20 tokens with total supply greater than 100,000,000, displaying symbol, name, contract address, and total supply from the token_metas table.

[Assistant] SELECT symbol, name, contract_address, total_supply FROM token_metas WHERE total_supply > '100000000';

[User] Include the number of decimals for each token and the latest USD price by joining with token_prices_latest.

[Assistant] SELECT tm.symbol, tm.name, tm.contract_address, tm.total_supply, tm.decimals, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.total_supply > '100000000';

[User] Filter the results to only include tokens where the latest USD price is less than 1.0.

[Assistant] SELECT tm.symbol, tm.name, tm.contract_address, tm.total_supply, tm.decimals, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.total_supply > '100000000' AND tpl.price < 1.0;

[User] Order the results by total supply descending and limit to the top 15 tokens.

[Assistant] SELECT tm.symbol, tm.name, tm.contract_address, tm.total_supply, tm.decimals, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.total_supply > '100000000' AND tpl.price < 1.0 ORDER BY CAST(tm.total_supply AS REAL) DESC LIMIT 15;


System:
You are very professional for database language writing. You 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 token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision,  -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )
CREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )
CREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL,  -- the snapshot time of record, converted from original timestamp chain character varying(128) NOT NULL, -- the chain that the token resides address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX exchange character varying(512) NOT NULL, -- a centralized exchange name token_address character varying(128) NOT NULL, -- token contract address token_symbol character varying(512), --token symbol balance numeric(38,10), -- token balance usd_value numeric(38,14), -- value of the token held in USD price double precision, --price of the token in USD ,PRIMARY KEY (snapshot_time, exchange, address, chain, token_address) )
CREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )
CREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )
CREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )

[User] Could you list projects that have completed more than one fundraising round, showing the project name and the number of rounds?

[Assistant] SELECT project_name, COUNT(*) AS round_count FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1 ORDER BY round_count DESC;

[User] For these projects with multiple rounds, can you show the earliest and latest investment date and the corresponding investment value for each project?

[Assistant] WITH ProjectRounds AS ( SELECT project_id, project_name, investment_value, investment_date, ROW_NUMBER() OVER(PARTITION BY project_id ORDER BY investment_date ASC) as rn_earliest, ROW_NUMBER() OVER(PARTITION BY project_id ORDER BY investment_date DESC) as rn_latest FROM project_fundraising_record ) SELECT pr_earliest.project_name, pr_earliest.investment_date AS earliest_date, pr_earliest.investment_value AS earliest_investment, pr_latest.investment_date AS latest_date, pr_latest.investment_value AS latest_investment FROM ProjectRounds pr_earliest JOIN ProjectRounds pr_latest ON pr_earliest.project_id = pr_latest.project_id WHERE pr_earliest.rn_earliest = 1 AND pr_latest.rn_latest = 1 AND pr_earliest.project_id IN ( SELECT project_id FROM project_fundraising_record GROUP BY project_id HAVING COUNT(*) > 1 ) ORDER BY pr_latest.investment_date DESC;

[User] Now, for those projects that also have a matching token, link the latest investment value to the token's current price and its smart money ROI. Match project name to token symbol or name case-insensitively.

[Assistant] WITH ProjectLatestRound AS ( SELECT project_id, project_name, investment_value, investment_date, ROW_NUMBER() OVER(PARTITION BY project_id ORDER BY investment_date DESC) as rn FROM project_fundraising_record WHERE project_id IN ( SELECT project_id FROM project_fundraising_record GROUP BY project_id HAVING COUNT(*) > 1 ) ) SELECT plr.project_name, plr.investment_value AS latest_investment, tbi.token_symbol, tbi.price AS current_token_price, smp.roi AS smart_money_roi FROM ProjectLatestRound plr JOIN token_basic_info tbi ON LOWER(tbi.token_symbol) LIKE '%' || LOWER(plr.project_name) || '%' OR LOWER(plr.project_name) LIKE '%' || LOWER(tbi.token_symbol) || '%' OR LOWER(tbi.token_name) LIKE '%' || LOWER(plr.project_name) || '%' OR LOWER(plr.project_name) LIKE '%' || LOWER(tbi.token_name) || '%' LEFT JOIN smart_money_token_performance smp ON tbi.token_symbol = smp.token_symbol WHERE plr.rn = 1;

[User] Filter the results to only include projects where the latest investment value is greater than $1,000,000 AND the token's smart money ROI is positive (greater than 0). Order the results by smart money ROI descending and show the top 10.

[Assistant] WITH ProjectLatestRound AS ( SELECT project_id, project_name, investment_value, investment_date, ROW_NUMBER() OVER(PARTITION BY project_id ORDER BY investment_date DESC) as rn FROM project_fundraising_record WHERE project_id IN ( SELECT project_id FROM project_fundraising_record GROUP BY project_id HAVING COUNT(*) > 1 ) ) SELECT plr.project_name, plr.investment_value AS latest_investment, tbi.token_symbol, tbi.price AS current_token_price, smp.roi AS smart_money_roi FROM ProjectLatestRound plr JOIN token_basic_info tbi ON LOWER(tbi.token_symbol) LIKE '%' || LOWER(plr.project_name) || '%' OR LOWER(plr.project_name) LIKE '%' || LOWER(tbi.token_symbol) || '%' OR LOWER(tbi.token_name) LIKE '%' || LOWER(plr.project_name) || '%' OR LOWER(plr.project_name) LIKE '%' || LOWER(tbi.token_name) || '%' JOIN smart_money_token_performance smp ON tbi.token_symbol = smp.token_symbol WHERE plr.rn = 1 AND plr.investment_value > 1000000 AND smp.roi > 0 ORDER BY smp.roi DESC LIMIT 10;


System:
You are very professional for database language writing. You 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.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )
CREATE TABLE financial_services.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) )

[User] Retrieve each customer_id, first_name, last_name, and close_price for market_data entries that occurred on the day of their account creation.

[Assistant] SELECT c.customer_id, c.first_name, c.last_name, md.close_price FROM financial_services.customers c JOIN financial_services.market_data md ON DATE(c.created_at) = DATE(md.data_timestamp);

[User] Actually, I want the adjusted_close_price instead of close_price.

[Assistant] SELECT c.customer_id, c.first_name, c.last_name, md.adjusted_close_price FROM financial_services.customers c JOIN financial_services.market_data md ON DATE(c.created_at) = DATE(md.data_timestamp);

[User] And only include records where the volume is greater than 1000.

[Assistant] SELECT c.customer_id, c.first_name, c.last_name, md.adjusted_close_price FROM financial_services.customers c JOIN financial_services.market_data md ON DATE(c.created_at) = DATE(md.data_timestamp) WHERE md.volume > 1000;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )
CREATE TABLE insurance.claims (
    claim_id character varying(64) NOT NULL, -- unique identifier for the claim
    policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)
    customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)
    incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim
    reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported
    description text NOT NULL, -- detailed description of the incident and claim
    estimated_loss numeric(15, 2), -- initial estimated cost of the loss
    status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled
    settlement_amount numeric(15, 2), -- final amount paid out
    settlement_date date,
    claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)
    police_report_number character varying(100),
    PRIMARY KEY (claim_id)
)
CREATE TABLE insurance.insurance_products (
    product_id character varying(64) NOT NULL, -- unique identifier for the insurance product
    product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')
    product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'
    description text, -- detailed description of the product
    base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments
    coverage_details text, -- details about what is covered (could be JSON or structured text)
    underwriting_rules text, -- rules used for assessing risk and eligibility
    is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp,
    PRIMARY KEY (product_id)
)
CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )

[User] Show the total number of customers in each state.

[Assistant]
SELECT
  state,
  COUNT(customer_id)
FROM insurance.customers
GROUP BY
  state;


System:
You are very professional for database language writing. You 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.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 )

[User] I need a list showing each patient along with their current primary insurance policy number and their immediately previous primary policy number.

[Assistant]
SELECT ci.patient_id,
       ci.policy_number AS current_policy,
       pi.policy_number AS previous_policy
FROM healthcare.patient_insurance ci
LEFT JOIN healthcare.patient_insurance pi
  ON ci.patient_id = pi.patient_id
  AND pi.is_primary = TRUE
  AND pi.effective_date < ci.effective_date
WHERE ci.is_primary = TRUE
  AND (ci.expiration_date IS NULL OR ci.expiration_date > CURRENT_DATE)
  AND pi.effective_date = (
      SELECT MAX(pii.effective_date)
      FROM healthcare.patient_insurance pii
      WHERE pii.patient_id = ci.patient_id
        AND pii.is_primary = TRUE
        AND pii.effective_date < ci.effective_date
  );

[User] Actually, I only want to include previous policies that have an expiration_date set.

[Assistant]
SELECT ci.patient_id,
       ci.policy_number AS current_policy,
       pi.policy_number AS previous_policy
FROM healthcare.patient_insurance ci
LEFT JOIN healthcare.patient_insurance pi
  ON ci.patient_id = pi.patient_id
  AND pi.is_primary = TRUE
  AND pi.expiration_date IS NOT NULL
  AND pi.effective_date = (
      SELECT MAX(pii.effective_date)
      FROM healthcare.patient_insurance pii
      WHERE pii.patient_id = ci.patient_id
        AND pii.is_primary = TRUE
        AND pii.expiration_date IS NOT NULL
        AND pii.effective_date < ci.effective_date
  )
WHERE ci.is_primary = TRUE
  AND (ci.expiration_date IS NULL OR ci.expiration_date > CURRENT_DATE);


System:
You are very professional for database language writing. You 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, 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 )

[User] Can you show me a list of all active services along with their agency IDs and categories?

[Assistant] SELECT service_id, agency_id, service_name, category FROM government_services.services WHERE is_active = TRUE;

[User] Actually, only include services where the standard fee is less than 50.

[Assistant] SELECT service_id, agency_id, service_name, category FROM government_services.services WHERE is_active = TRUE AND standard_fee < 50;


System:
You are very professional for database language writing. You 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, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )

[User] How many games are available on each platform?

[Assistant]
SELECT platform, COUNT(*) AS game_count
FROM gaming_technology.games
GROUP BY platform;

[User] Exclude platforms with fewer than five games.

[Assistant]
SELECT platform, COUNT(*) AS game_count
FROM gaming_technology.games
GROUP BY platform
HAVING COUNT(*) >= 5;

[User] Also show the earliest release_date for each platform.

[Assistant]
SELECT platform, COUNT(*) AS game_count, MIN(release_date) AS first_release
FROM gaming_technology.games
GROUP BY platform
HAVING COUNT(*) >= 5;

[User] Finally, order by game_count descending.

[Assistant]
SELECT platform, COUNT(*) AS game_count, MIN(release_date) AS first_release
FROM gaming_technology.games
GROUP BY platform
HAVING COUNT(*) >= 5
ORDER BY game_count DESC;


System:
You are very professional for database language writing. You 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 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 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.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) )

[User] Show the count of applications submitted per day for the last 7 days. Include the date and application_count, ordered by date ascending.

[Assistant]
SELECT CAST(submitted_at AS date) AS date,
       COUNT(*) AS application_count
FROM government_services.applications
WHERE submitted_at >= CURRENT_DATE - INTERVAL '7 days'
GROUP BY CAST(submitted_at AS date)
ORDER BY date ASC;


System:
You are very professional for database language writing. You 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 )

[User] Show me all drivers hired in 2023, including their full name and email address.

[Assistant] SELECT first_name, last_name, email FROM transportation.drivers WHERE hire_date >= '2023-01-01' AND hire_date < '2024-01-01';

[User] Just provide their license numbers and order the results by hire date descending.

[Assistant] SELECT license_number FROM transportation.drivers WHERE hire_date >= '2023-01-01' AND hire_date < '2024-01-01' ORDER BY hire_date DESC;


System:
You are very professional for database language writing. You 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) )

[User] Show me all reservations with their reservation_id, room_number, room status, and check_in_date.

[Assistant]
SELECT r.reservation_id,
       rm.room_number,
       rm.status AS room_status,
       r.check_in_date
FROM hospitality_technology.reservations r
LEFT JOIN hospitality_technology.rooms rm
  ON r.room_id = rm.room_id;


System:
You are very professional for database language writing. You 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 NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition
    game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to
    name character varying(150) NOT NULL, -- name of the achievement
    description text NOT NULL, -- how to unlock the achievement
    icon_url character varying(255), -- URL for the achievement's icon
    points integer DEFAULT 0, -- points awarded for unlocking (optional)
    hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked
    PRIMARY KEY (achievement_id)
    -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)
)

[User] Show me the count of achievements that are hidden versus those that are not hidden.

[Assistant] SELECT hidden, COUNT(*) FROM achievements GROUP BY hidden;

[User] Include the average points for each group as well.

[Assistant] SELECT hidden, COUNT(*), AVG(points) FROM achievements GROUP BY hidden;

[User] Could you also add the average length of the description for each group?

[Assistant] SELECT hidden, COUNT(*), AVG(points), AVG(LENGTH(description)) FROM achievements GROUP BY hidden;

[User] Filter the results to only show groups that have more than 5 achievements.

[Assistant] SELECT hidden, COUNT(*), AVG(points), AVG(LENGTH(description)) FROM achievements GROUP BY hidden HAVING COUNT(*) > 5;