[User] List the name of NFTs and their contract name, along with the symbol and total supply from the token information table, for NFTs on the 'ethereum' blockchain.

[Assistant] SELECT T1.name, T1.contract_name, T2.symbol, T2.total_supply FROM nft_metadata AS T1 JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'ethereum';

[User] Now, only show me the results where the total supply is greater than 1000000 and the NFT name starts with 'C'.

[Assistant] SELECT T1.name, T1.contract_name, T2.symbol, T2.total_supply FROM nft_metadata AS T1 JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'ethereum' AND CAST(T2.total_supply AS DECIMAL) > 1000000 AND T1.name LIKE 'C%';

System:
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(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )
CREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )
CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )
CREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )
CREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )
CREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )
CREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )
CREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )


[User] Count the number of transactions for each block that was created in 2023 and has a difficulty greater than 1000. Show the block ID and the transaction count.

[Assistant] SELECT B.block_id, COUNT(T.transaction_id) AS transaction_count FROM blockchain.blocks AS B JOIN blockchain.transactions AS T ON B.block_id = T.block_id WHERE B.timestamp >= '2023-01-01' AND B.timestamp < '2024-01-01' AND B.difficulty > 1000 GROUP BY B.block_id

[User] Only show blocks from that list that have more than 50 transactions.

[Assistant] SELECT B.block_id, COUNT(T.transaction_id) AS transaction_count FROM blockchain.blocks AS B JOIN blockchain.transactions AS T ON B.block_id = T.block_id WHERE B.timestamp >= '2023-01-01' AND B.timestamp < '2024-01-01' AND B.difficulty > 1000 GROUP BY B.block_id HAVING COUNT(T.transaction_id) > 50

[User] For those blocks, also include the total amount of all transactions within each block, and order the results by transaction count descending.

[Assistant] SELECT B.block_id, COUNT(T.transaction_id) AS transaction_count, SUM(T.amount) AS total_amount FROM blockchain.blocks AS B JOIN blockchain.transactions AS T ON B.block_id = T.block_id WHERE B.timestamp >= '2023-01-01' AND B.timestamp < '2024-01-01' AND B.difficulty > 1000 GROUP BY B.block_id HAVING COUNT(T.transaction_id) > 50 ORDER BY transaction_count DESC

System:
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.blocks ( block_id character varying(64) NOT NULL, previous_block_id character varying(64), timestamp timestamp NOT NULL, nonce integer NOT NULL, merkle_root character varying(128) NOT NULL, difficulty integer NOT NULL, PRIMARY KEY (block_id) )
CREATE TABLE blockchain.transactions ( transaction_id character varying(64) NOT NULL, block_id character varying(64) NOT NULL, sender_address character varying(128) NOT NULL, receiver_address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, timestamp timestamp NOT NULL, signature text NOT NULL, PRIMARY KEY (transaction_id) )
CREATE TABLE blockchain.nodes ( node_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (node_id) )
CREATE TABLE blockchain.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, PRIMARY KEY (user_id) )


[User] List the count of events for each contract deployed by address '0x123abc...'

[Assistant] SELECT c.address, COUNT(e.event_id) FROM web3.contracts c JOIN web3.events e ON c.contract_id = e.contract_id WHERE c.deployer_address = '0x123abc...' GROUP BY c.address;

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )
CREATE TABLE web3.events ( event_id 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) )
CREATE TABLE web3.token_transfers ( transfer_id character varying(64) NOT NULL, token_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128) NOT NULL, value numeric(38,14) NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (transfer_id) )
CREATE TABLE web3.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 web3.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )


[User] List the user ID and username for all users, ordered by username alphabetically.

[Assistant] SELECT user_id, username FROM blockchain.users ORDER BY username ASC;

[User] From that list, only show users whose username contains the word 'test'.

[Assistant] SELECT user_id, username FROM blockchain.users WHERE username LIKE '%test%' ORDER BY username ASC;

[User] Also include their email address in the results.

[Assistant] SELECT user_id, username, email FROM blockchain.users WHERE username LIKE '%test%' ORDER BY username ASC;

System:
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.users ( user_id.text, username.text, email.text, password_hash.text )


[User] Find the user ID with the most wallets and list their user ID and the total number of wallets they have.

[Assistant] SELECT user_id, COUNT(wallet_id) AS wallet_count FROM web3.wallets GROUP BY user_id ORDER BY wallet_count DESC LIMIT 1;

System:
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 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) )


[User] List all event names and their corresponding transaction IDs for events that occurred in July 2024.

[Assistant] SELECT event_name, transaction_id FROM web3.events WHERE emitted_at >= '2024-07-01 00:00:00' AND emitted_at < '2024-08-01 00:00:00';

[User] From that list, only show the entries where the event_name is 'Transfer' or 'Mint'.

[Assistant] SELECT event_name, transaction_id FROM web3.events WHERE emitted_at >= '2024-07-01 00:00:00' AND emitted_at < '2024-08-01 00:00:00' AND (event_name = 'Transfer' OR event_name = 'Mint');

[User] Instead of listing them, can you count how many 'Transfer' or 'Mint' events occurred in July 2024?

[Assistant] SELECT COUNT(*) FROM web3.events WHERE emitted_at >= '2024-07-01 00:00:00' AND emitted_at < '2024-08-01 00:00:00' AND (event_name = 'Transfer' OR event_name = 'Mint');

[User] For those events, show me the count for each contract_id.

[Assistant] SELECT contract_id, COUNT(*) FROM web3.events WHERE emitted_at >= '2024-07-01 00:00:00' AND emitted_at < '2024-08-01 00:00:00' AND (event_name = 'Transfer' OR event_name = 'Mint') GROUP BY contract_id;

System:
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 )


[User] List all users who have received any notification, showing their username and the total number of notifications they received. Assume a users table with user_id and username exists.

[Assistant] SELECT u.username, COUNT(n.notification_id) FROM users u JOIN notifications n ON u.user_id = n.user_id GROUP BY u.username

[User] Filter this to only include users who have received notifications that were sent before '2023-11-01', showing the same details.

[Assistant] SELECT u.username, COUNT(n.notification_id) FROM users u JOIN notifications n ON u.user_id = n.user_id WHERE n.sent_at < '2023-11-01' GROUP BY u.username

[User] For users who received notifications before '2023-11-01', show their username and the latest timestamp of a notification they received within that period.

[Assistant] SELECT u.username, MAX(n.sent_at) FROM users u JOIN notifications n ON u.user_id = n.user_id WHERE n.sent_at < '2023-11-01' GROUP BY u.username

System:
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 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.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )


[User] List the node ID, IP address, and port for all nodes last seen after '2024-06-01'.

[Assistant] SELECT node_id, ip_address, port FROM blockchain.nodes WHERE last_seen > '2024-06-01';

[User] How many nodes are running on port 80 or port 443?

[Assistant] SELECT COUNT(node_id) FROM blockchain.nodes WHERE port = 80 OR port = 443;

System:
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.nodes ( node_id text, ip_address text, port integer, last_seen timestamp )
CREATE TABLE blockchain.wallets ( wallet_id text, user_id text, address_id text, private_key text )
CREATE TABLE blockchain.users ( user_id text, username text, email text, password_hash text )


[User] List all users and the total quantity of orders they have placed for 'buy' orders.

[Assistant] SELECT t1.username, SUM(t2.quantity) FROM trading_platform.users AS t1 JOIN trading_platform.orders AS t2 ON t1.user_id = t2.user_id WHERE t2.order_type = 'buy' GROUP BY t1.username;

[User] Filter this list to only include users whose total buy quantity is greater than 100.

[Assistant] SELECT t1.username, SUM(t2.quantity) FROM trading_platform.users AS t1 JOIN trading_platform.orders AS t2 ON t1.user_id = t2.user_id WHERE t2.order_type = 'buy' GROUP BY t1.username HAVING SUM(t2.quantity) > 100;

[User] For those users, what is the average price of their 'buy' orders? Show username and average price.

[Assistant] SELECT t1.username, AVG(t2.price) FROM trading_platform.users AS t1 JOIN trading_platform.orders AS t2 ON t1.user_id = t2.user_id WHERE t2.order_type = 'buy' GROUP BY t1.username HAVING SUM(t2.quantity) > 100;

System:
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.orders ( order_id.text, user_id.text, wallet_id.text, asset_id.text, order_type.text, quantity.numeric, price.numeric, status.text, created_at.timestamp )
CREATE TABLE trading_platform.assets ( asset_id.text, name.text, symbol.text, type.text )
CREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )
CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id.text, user_id.text, status.text, reviewed_at.timestamp )
CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )


[User] Show me the name of each narrative and its 24-hour price change percentage.

[Assistant] SELECT narrative, price_change_percentage_24h FROM narrative_info

[User] Now, filter the list to only include narratives with a 24-hour price change greater than 5%. Order the results by the 24-hour price change descending.

[Assistant] SELECT narrative, price_change_percentage_24h FROM narrative_info WHERE price_change_percentage_24h > 5 ORDER BY price_change_percentage_24h DESC

System:
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 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 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] List the block ID and timestamp for all blocks that were mined after 2023-01-01 and also show the ID and timestamp of their direct successor block.

[Assistant] SELECT t1.block_id, t1.timestamp, t2.block_id AS successor_block_id, t2.timestamp AS successor_block_timestamp FROM blockchain.blocks AS t1 JOIN blockchain.blocks AS t2 ON t2.previous_block_id = t1.block_id WHERE t1.timestamp > '2023-01-01'

[User] From that list, filter the results to only include pairs where the successor block's difficulty is greater than 5000.

[Assistant] SELECT t1.block_id, t1.timestamp, t2.block_id AS successor_block_id, t2.timestamp AS successor_block_timestamp FROM blockchain.blocks AS t1 JOIN blockchain.blocks AS t2 ON t2.previous_block_id = t1.block_id WHERE t1.timestamp > '2023-01-01' AND t2.difficulty > 5000

System:
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.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer )


[User] What is the average difficulty and the maximum nonce value for all blocks recorded?

[Assistant] SELECT AVG(difficulty), MAX(nonce) FROM blockchain.blocks


[User] List all usernames and the ID of the wallets they own.

[Assistant] SELECT t1.username, t2.wallet_id FROM blockchain.users AS t1 INNER JOIN blockchain.wallets AS t2 ON t1.user_id = t2.user_id;

[User] Filter that list to only show wallets whose ID starts with 'wlt_abc'.

[Assistant] SELECT t1.username, t2.wallet_id FROM blockchain.users AS t1 INNER JOIN blockchain.wallets AS t2 ON t1.user_id = t2.user_id WHERE t2.wallet_id LIKE 'wlt_abc%';

[User] For those users, also include their email address.

[Assistant] SELECT t1.username, t1.email, t2.wallet_id FROM blockchain.users AS t1 INNER JOIN blockchain.wallets AS t2 ON t1.user_id = t2.user_id WHERE t2.wallet_id LIKE 'wlt_abc%';


[User] Show me the name of all NFTs and their collection names for collections named 'CryptoPunks'.

[Assistant] SELECT t1.name AS nft_name, t2.name AS collection_name FROM nft_metadata AS t1 JOIN nft_collections AS t2 ON t1.contract_address = t2.contract_address WHERE t2.name = 'CryptoPunks'

[User] Okay, now filter that list to only include NFTs with a rarity rank less than 50.

[Assistant] SELECT t1.name AS nft_name, t2.name AS collection_name FROM nft_metadata AS t1 JOIN nft_collections AS t2 ON t1.contract_address = t2.contract_address WHERE t2.name = 'CryptoPunks' AND t1.rarity_rank < 50

[User] For those specific NFTs, also show the owner and the mint price. And only include those owned by address '0xdef...456'.

[Assistant] SELECT t1.name AS nft_name, t2.name AS collection_name, t1.owner, t1.mint_price FROM nft_metadata AS t1 JOIN nft_collections AS t2 ON t1.contract_address = t2.contract_address WHERE t2.name = 'CryptoPunks' AND t1.rarity_rank < 50 AND t1.owner = '0xdef...456'

[User] Instead of listing them, just tell me how many NFTs meet all these criteria.

[Assistant] SELECT COUNT(*) FROM nft_metadata AS t1 JOIN nft_collections AS t2 ON t1.contract_address = t2.contract_address WHERE t2.name = 'CryptoPunks' AND t1.rarity_rank < 50 AND t1.owner = '0xdef...456'

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )
CREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )
CREATE TABLE erc20_balances_historical ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.integer )
CREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )
CREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )
CREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )
CREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )
CREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )
CREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )
CREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )
CREATE TABLE token_info ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )
CREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )
CREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )
CREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )
CREATE TABLE token_activities_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 )


[User] For Sui coins owned by address '0xabc...xyz', list the balance and their symbol by joining the coins and metadata tables.

[Assistant] SELECT T1.balance, T2.symbol FROM sui_coins AS T1 JOIN sui_coins_metadata AS T2 ON T1.coin_type = T2.coin_type WHERE T1.owner = '0xabc...xyz';

[User] Filter the results to only include coins with the symbol 'USDC'.

[Assistant] SELECT T1.balance, T2.symbol FROM sui_coins AS T1 JOIN sui_coins_metadata AS T2 ON T1.coin_type = T2.coin_type WHERE T1.owner = '0xabc...xyz' AND T2.symbol = 'USDC';

[User] Instead of listing all, just tell me the total balance of 'USDC' for that owner.

[Assistant] SELECT SUM(CAST(T1.balance AS DECIMAL)) FROM sui_coins AS T1 JOIN sui_coins_metadata AS T2 ON T1.coin_type = T2.coin_type WHERE T1.owner = '0xabc...xyz' AND T2.symbol = 'USDC';


[User] List all unspent transaction outputs (UTXOs), showing their transaction ID and amount.

[Assistant] SELECT transaction_id, amount FROM trading_platform.utxos WHERE spent = false;

[User] Calculate the total amount across all unspent UTXOs.

[Assistant] SELECT SUM(amount) AS total_unspent_amount FROM trading_platform.utxos WHERE spent = false;

[User] Show the total unspent amount for each unique address.

[Assistant] SELECT address, SUM(amount) AS total_unspent_amount FROM trading_platform.utxos WHERE spent = false GROUP BY address;

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )
CREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )
CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )
CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )
CREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )


[User] List all trades, including the status of the corresponding order.

[Assistant] SELECT t.trade_id, t.order_id, o.status FROM trading_platform.trades t JOIN trading_platform.orders o ON t.order_id = o.order_id;

[User] Filter the list to only include trades originating from orders with status 'filled'.

[Assistant] SELECT t.trade_id, t.order_id, o.status FROM trading_platform.trades t JOIN trading_platform.orders o ON t.order_id = o.order_id WHERE o.status = 'filled';

[User] For these trades from 'filled' orders, what is the average price traded for each asset ID?

[Assistant] SELECT t.asset_id, AVG(t.price) FROM trading_platform.trades t JOIN trading_platform.orders o ON t.order_id = o.order_id WHERE o.status = 'filled' GROUP BY t.asset_id;

System:
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 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.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 )


[User] Show me the deployer address and the count of contracts they have deployed on the 'mainnet' network, but only for deployers who have deployed more than 5 contracts on mainnet. Sort the results by the count in descending order.

[Assistant] SELECT deployer_address, COUNT(*) FROM web3.contracts WHERE network_id = 'mainnet' GROUP BY deployer_address HAVING COUNT(*) > 5 ORDER BY COUNT(*) DESC;

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts ( contract_id text PRIMARY KEY, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )


[User] List all users along with their associated wallet addresses.

[Assistant] SELECT u.username, w.address FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id;

[User] Now, filter this list to only show users who have placed at least one order.

[Assistant] SELECT DISTINCT u.username, w.address FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id JOIN trading_platform.orders o ON u.user_id = o.user_id;

[User] For these users, show the latest timestamp of any order they placed, alongside their username and wallet address.

[Assistant] SELECT u.username, w.address, MAX(o.created_at) AS latest_order_time FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id JOIN trading_platform.orders o ON u.user_id = o.user_id GROUP BY u.user_id, u.username, w.wallet_id, w.address;

System:
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 character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )
CREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )
CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )
CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_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 character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )
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.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )
CREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )


[User] Find all NFTs with a rarity rank less than 100 and show their name and the name of their collection.

[Assistant] SELECT nm.name AS nft_name, nc.name AS collection_name FROM nft_metadata nm JOIN nft_collections nc ON nm.contract_address = nc.contract_address WHERE nm.rarity_rank < 100;

[User] Filter that further to only include NFTs from collections named 'Bored Ape Yacht Club'.

[Assistant] SELECT nm.name AS nft_name, nc.name AS collection_name FROM nft_metadata nm JOIN nft_collections nc ON nm.contract_address = nc.contract_address WHERE nm.rarity_rank < 100 AND nc.name = 'Bored Ape Yacht Club';

System:
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, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )
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 varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )
CREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )
CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )
CREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )
CREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )
CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )
CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )
CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
CREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
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 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] Show me the total number of users.

[Assistant] SELECT COUNT(*) FROM web3.users;

[User] Now, show me the username and email address for the user with the most recently created account.

[Assistant] SELECT username, email FROM web3.users ORDER BY created_at DESC LIMIT 1;

System:
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.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )


[User] What is the timestamp of the most recent log entry for each user?

[Assistant] SELECT user_id, MAX(logged_at) AS latest_log_time FROM logs GROUP BY user_id;

[User] For each user, show the action and timestamp of their single most recent log entry.

[Assistant] SELECT t1.user_id, t1.action, t1.logged_at FROM logs t1 INNER JOIN ( SELECT user_id, MAX(logged_at) AS max_logged_at FROM logs GROUP BY user_id ) t2 ON t1.user_id = t2.user_id AND t1.logged_at = t2.max_logged_at;

[User] Only show users whose most recent log action was 'logout' and occurred after November 1st, 2023.

[Assistant] SELECT t1.user_id, t1.action, t1.logged_at FROM logs t1 INNER JOIN ( SELECT user_id, MAX(logged_at) AS max_logged_at FROM logs GROUP BY user_id ) t2 ON t1.user_id = t2.user_id AND t1.logged_at = t2.max_logged_at WHERE t1.action = 'logout' AND t1.logged_at >= '2023-11-01 00:00:00';

System:
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.logs ( log_id.text, user_id.text, action.text, details.text, logged_at.timestamp )


[User] List the transaction IDs and timestamps for all transactions sent to the contract address of the token with the symbol 'USDC'.

[Assistant] SELECT T1.transaction_id, T1.timestamp FROM web3.transactions AS T1 JOIN web3.tokens AS T2 ON T1.to_address = T2.contract_address WHERE T2.token_symbol = 'USDC';

System:
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 )
CREATE TABLE web3.tokens ( token_id.text, contract_address.text, token_name.text, token_symbol.text, decimals.integer, total_supply.numeric )


[User] How many wallets were created in the year 2023?

[Assistant] SELECT COUNT(*) FROM web3.wallets WHERE created_at >= '2023-01-01 00:00:00' AND created_at < '2024-01-01 00:00:00';

[User] Okay, instead of the count, show me the wallet ID and creation date for wallets created in January 2023.

[Assistant] SELECT wallet_id, created_at FROM web3.wallets WHERE created_at >= '2023-01-01 00:00:00' AND created_at < '2023-02-01 00:00:00';

[User] Actually, only show me the ones belonging to user ID 'user_example123'.

[Assistant] SELECT wallet_id, created_at FROM web3.wallets WHERE created_at >= '2023-01-01 00:00:00' AND created_at < '2023-02-01 00:00:00' AND user_id = 'user_example123';

[User] Can you sort these by creation date in ascending order and only show the first 5?

[Assistant] SELECT wallet_id, created_at FROM web3.wallets WHERE created_at >= '2023-01-01 00:00:00' AND created_at < '2023-02-01 00:00:00' AND user_id = 'user_example123' ORDER BY created_at ASC LIMIT 5;

System:
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 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)
)


[User] List tokens that exist in both the token basic information and the DEX pool information tables. For these tokens, show their symbol, the chain they are on, the current price from basic info, and the liquidity from the DEX pool info.

[Assistant] SELECT T1.token_symbol, T1.chain, T1.price, T2.liquidity FROM token_basic_info AS T1 JOIN token_dexpool_info AS T2 ON T1.token_symbol = T2.token_symbol AND T1.chain = T2.chain


[User] List the name and latest price for all tokens that have a price listed.

[Assistant] SELECT t1.name, t2.price FROM token_metas AS t1 JOIN token_prices AS t2 ON t1.contract_address = t2.address WHERE t2.timestamp IN (SELECT MAX(timestamp) FROM token_prices GROUP BY address)

[User] Okay, now include the blockchain name for the price data and filter the results to only show tokens on the 'ethereum' blockchain.

[Assistant] SELECT t1.name, t2.price, t2.blockchain FROM token_metas AS t1 JOIN token_prices AS t2 ON t1.contract_address = t2.address WHERE t2.timestamp IN (SELECT MAX(timestamp) FROM token_prices GROUP BY address) AND t2.blockchain = 'ethereum'

[User] Sort the results by price in descending order.

[Assistant] SELECT t1.name, t2.price, t2.blockchain FROM token_metas AS t1 JOIN token_prices AS t2 ON t1.contract_address = t2.address WHERE t2.timestamp IN (SELECT MAX(timestamp) FROM token_prices GROUP BY address) AND t2.blockchain = 'ethereum' ORDER BY t2.price DESC


[User] How many smart money addresses are recorded for each chain?

[Assistant] SELECT chain, COUNT(address) FROM smart_money_profit GROUP BY chain;

[User] Now, only show chains that have more than 100 recorded addresses.

[Assistant] SELECT chain, COUNT(address) FROM smart_money_profit GROUP BY chain HAVING COUNT(address) > 100;

[User] Can you order the results by the number of addresses in descending order?

[Assistant] SELECT chain, COUNT(address) FROM smart_money_profit GROUP BY chain HAVING COUNT(address) > 100 ORDER BY COUNT(address) DESC;

[User] Also, include the average ROI for addresses on these chains.

[Assistant] SELECT chain, COUNT(address), AVG(roi) FROM smart_money_profit GROUP BY chain HAVING COUNT(address) > 100 ORDER BY COUNT(address) DESC;

System:
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_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) )


[User] Show the name and description for all dapps.

[Assistant] SELECT name, description FROM trading_platform.dapps;

[User] Refine this to show only dapps whose description contains the word 'management'.

[Assistant] SELECT name, description FROM trading_platform.dapps WHERE description LIKE '%management%';

[User] For these dapps, list only their name and URL.

[Assistant] SELECT name, url FROM trading_platform.dapps WHERE description LIKE '%management%';


[User] List the names of NFT collections and the wallet addresses that hold NFTs from those collections.

[Assistant] SELECT DISTINCT T1.name, T2.wallet_address FROM nft_collections AS T1 JOIN nft_holder_historical AS T2 ON T1.contract_address = T2.contract_address;

System:
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, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )
CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )
CREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )
CREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )
CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )
CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )
CREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
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 transaction IDs, sender addresses, and amounts for transactions received by '0xFEDCBA9876543210FEDCBA9876543210FEDCBA98' between '2023-01-01' and '2023-03-31'.

[Assistant] SELECT transaction_id, sender_address, amount FROM blockchain.transactions WHERE receiver_address = '0xFEDCBA9876543210FEDCBA9876543210FEDCBA98' AND timestamp BETWEEN '2023-01-01' AND '2023-03-31';

System:
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 character varying(64) NOT NULL,  -- unique identifier for the transaction
    block_id character varying(64) NOT NULL, -- identifier of the block containing the transaction
    sender_address character varying(128) NOT NULL, -- address of the sender
    receiver_address character varying(128) NOT NULL, -- address of the receiver
    amount numeric(38,14) NOT NULL, -- amount transferred
    timestamp timestamp NOT NULL, -- time when the transaction was created
    signature text NOT NULL, -- digital signature of the transaction
    PRIMARY KEY (transaction_id)
)


[User] List the block ID, timestamp, and difficulty for all blocks created before '2024-01-01', ordered by timestamp in descending order.

[Assistant] SELECT block_id, timestamp, difficulty FROM blockchain.blocks WHERE timestamp < '2024-01-01' ORDER BY timestamp DESC;

[User] Now, filter those results to only show blocks with a difficulty between 8000 and 12000.

[Assistant] SELECT block_id, timestamp, difficulty FROM blockchain.blocks WHERE timestamp < '2024-01-01' AND difficulty BETWEEN 8000 AND 12000 ORDER BY timestamp DESC;

System:
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.blocks ( block_id.text, previous_block_id.text, timestamp.timestamp, nonce.integer, merkle_root.text, difficulty.integer )
CREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )
CREATE TABLE blockchain.smart_contracts ( contract_id.text, creator_address.text, code.text, timestamp.timestamp )


[User] Show me the user ID, wallet address, and transaction ID for the first 20 transactions sent from any user's wallet.

[Assistant] SELECT W.user_id, W.address, T.transaction_id FROM web3.wallets W JOIN web3.transactions T ON W.address = T.from_address LIMIT 20;

[User] Instead of listing individual transactions, please count how many transactions have originated from each user's wallets.

[Assistant] SELECT W.user_id, COUNT(T.transaction_id) FROM web3.wallets W JOIN web3.transactions T ON W.address = T.from_address GROUP BY W.user_id;

[User] Can you filter this list to only show users who have originated more than 100 transactions?

[Assistant] SELECT W.user_id, COUNT(T.transaction_id) FROM web3.wallets W JOIN web3.transactions T ON W.address = T.from_address GROUP BY W.user_id HAVING COUNT(T.transaction_id) > 100;

[User] Please sort the results by the transaction count in descending order.

[Assistant] SELECT W.user_id, COUNT(T.transaction_id) FROM web3.wallets W JOIN web3.transactions T ON W.address = T.from_address GROUP BY W.user_id HAVING COUNT(T.transaction_id) > 100 ORDER BY COUNT(T.transaction_id) DESC;

System:
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 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.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )


[User] Show me all records from the project fundraising table, listing the project name, rounds name, and investment value.

[Assistant] SELECT project_name, rounds_name, investment_value FROM project_fundraising_record;

[User] Now, only show me records where the investment value is greater than 1000000.

[Assistant] SELECT project_name, rounds_name, investment_value FROM project_fundraising_record WHERE investment_value > 1000000;

[User] Can you show me the smart money token inflows? I'm interested in the token symbol, the USD value of the inflow, and the chain it occurred on.

[Assistant] SELECT token_symbol, usd_value, chain FROM smart_money_token_inflow;

[User] Filter that inflow list to only show inflows for the 'Ethereum' chain.

[Assistant] SELECT token_symbol, usd_value, chain FROM smart_money_token_inflow WHERE chain = 'Ethereum';

System:
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 character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )
CREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, top_3_coins text, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, market_cap double precision, volume_24h double precision, trend_rank bigint, token_num bigint )
CREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )
CREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, token_symbol character varying(100), token_amount numeric(38,2), usd_value numeric(38,2), avg_price numeric(38,6), type int, address_amount integer, narrative character varying(100), chain character varying(100) )


[User] Show me all transactions that occurred in the last week.

[Assistant] SELECT * FROM web3.transactions WHERE timestamp >= NOW() - INTERVAL '7 days';

[User] From that list, only show the ones with a status of 'failed'.

[Assistant] SELECT * FROM web3.transactions WHERE timestamp >= NOW() - INTERVAL '7 days' AND status = 'failed';


[User] Show me the user ID, wallet ID, contract ID, creator address, and timestamp for smart contracts created by addresses associated with any wallet.

[Assistant] SELECT w.user_id, w.wallet_id, sc.contract_id, sc.creator_address, sc.timestamp FROM blockchain.wallets w JOIN blockchain.smart_contracts sc ON w.address_id = sc.creator_address;

[User] From that list, filter to only include contracts created after '2023-12-31'.

[Assistant] SELECT w.user_id, w.wallet_id, sc.contract_id, sc.creator_address, sc.timestamp FROM blockchain.wallets w JOIN blockchain.smart_contracts sc ON w.address_id = sc.creator_address WHERE sc.timestamp > '2023-12-31';


[User] List all distinct email domains found in the user email addresses.

[Assistant] SELECT DISTINCT SUBSTRING(email, INSTR(email, '@') + 1) AS email_domain FROM web3.users;

[User] For each domain, show the count of users.

[Assistant] SELECT SUBSTRING(email, INSTR(email, '@') + 1) AS email_domain, COUNT(*) FROM web3.users GROUP BY email_domain;

System:
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.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )


[User] List tokens associated with the 'AI' narrative. For each token, show its symbol and current price. Also include the 24-hour volume for the 'AI' narrative itself.

[Assistant] SELECT T1.token_symbol, T1.price, T2.volume_24h FROM token_basic_info AS T1 JOIN narrative_info AS T2 ON T1.narrative = T2.narrative WHERE T2.narrative = 'AI';


[User] List the usernames and emails for users created in the last year.

[Assistant] SELECT username, email FROM web3.users WHERE created_at >= NOW() - INTERVAL '1 year';

[User] Filter this list to only include users whose email contains 'example'.

[Assistant] SELECT username, email FROM web3.users WHERE created_at >= NOW() - INTERVAL '1 year' AND email LIKE '%example%';

[User] Order the list by username in ascending order.

[Assistant] SELECT username, email FROM web3.users WHERE created_at >= NOW() - INTERVAL '1 year' AND email LIKE '%example%' ORDER BY username ASC;

[User] Also, show me their creation date.

[Assistant] SELECT username, email, created_at FROM web3.users WHERE created_at >= NOW() - INTERVAL '1 year' AND email LIKE '%example%' ORDER BY username ASC;

System:
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.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) )


[User] Count users whose email address ends with '.com'.

[Assistant] SELECT COUNT(*) FROM web3.users WHERE email LIKE '%.com';

[User] Now, show me the username and email for those users instead of just the count.

[Assistant] SELECT username, email FROM web3.users WHERE email LIKE '%.com';

[User] Also, filter this list to only include users created in the year 2024.

[Assistant] SELECT username, email FROM web3.users WHERE email LIKE '%.com' AND EXTRACT(YEAR FROM created_at) = 2024;

[User] Sort the results by username alphabetically.

[Assistant] SELECT username, email FROM web3.users WHERE email LIKE '%.com' AND EXTRACT(YEAR FROM created_at) = 2024 ORDER BY username ASC;


[User] Show pairs of fundraising records for the same project, including the round names and their investment values.

[Assistant] SELECT T1.project_name, T1.rounds_name AS round1, T1.investment_value AS value1, T2.rounds_name AS round2, T2.investment_value AS value2 FROM project_fundraising_record T1 JOIN project_fundraising_record T2 ON T1.project_id = T2.project_id AND T1.id <> T2.id;

[User] Filter this list to only show pairs where the first round listed occurred *before* the second round listed, based on the investment date.

[Assistant] SELECT T1.project_name, T1.rounds_name AS round1, T1.investment_value AS value1, T2.rounds_name AS round2, T2.investment_value AS value2, T1.investment_date AS date1, T2.investment_date AS date2 FROM project_fundraising_record T1 JOIN project_fundraising_record T2 ON T1.project_id = T2.project_id AND T1.id <> T2.id WHERE T1.investment_date < T2.investment_date;

System:
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",


[User] Show me the user ID, username, and email for all users.

[Assistant] SELECT user_id, username, email FROM blockchain.users;

[User] Now, only show the users whose username starts with 'alpha'.

[Assistant] SELECT user_id, username, email FROM blockchain.users WHERE username LIKE 'alpha%';

System:
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.users ( user_id.text, username.text, email.text, password_hash.text )


[User] What is the total USD value of smart money token inflows for each chain?

[Assistant] SELECT chain, SUM(usd_value) AS total_usd_inflow FROM smart_money_token_inflow GROUP BY chain ORDER BY total_usd_inflow DESC;

[User] Now, show me the total USD inflow for each chain, but only for inflows associated with the 'AI' narrative.

[Assistant] SELECT chain, SUM(usd_value) AS total_usd_inflow FROM smart_money_token_inflow WHERE narrative = 'AI' GROUP BY chain ORDER BY total_usd_inflow DESC;

System:
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 )


[User] Find projects that have both fundraising records and basic token information. Display the project name, fundraising round name, investment value, and the token's current price.

[Assistant] SELECT T1.project_name, T1.rounds_name, T1.investment_value, T2.price FROM project_fundraising_record AS T1 INNER JOIN token_basic_info AS T2 ON T1.project_name = T2.token_symbol;

[User] Modify the previous query to only include projects with an investment value greater than 500000 and where the token is on the 'BNB' chain.

[Assistant] SELECT T1.project_name, T1.rounds_name, T1.investment_value, T2.price FROM project_fundraising_record AS T1 INNER JOIN token_basic_info AS T2 ON T1.project_name = T2.token_symbol WHERE T1.investment_value > 500000 AND T2.chain = 'BNB';


[User] Show me the wallet ID and address for user 'user_abc'.

[Assistant] SELECT wallet_id, address FROM web3.wallets WHERE user_id = 'user_abc';

[User] Could you sort those wallets by their creation date in descending order?

[Assistant] SELECT wallet_id, address FROM web3.wallets WHERE user_id = 'user_abc' ORDER BY created_at DESC;

System:
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, user_id text, address text, private_key text, created_at timestamp )


[User] For the ticker 'doge', what are the different types of activities recorded in the `token_activities_bitcoin` table?

[Assistant] SELECT DISTINCT type FROM token_activities_bitcoin WHERE tick = 'doge'

[User] Show me the amount, from address, and to address for 'mint' activities of 'doge'.

[Assistant] SELECT amt, from_address, to_address FROM token_activities_bitcoin WHERE tick = 'doge' AND type = 'mint'

[User] How many such 'mint' activities are there for 'doge'?

[Assistant] SELECT COUNT(*) FROM token_activities_bitcoin WHERE tick = 'doge' AND type = 'mint'

[User] Now, from the `token_info_bitcoin` table, what is the maximum supply for the 'doge' ticker?

[Assistant] SELECT max_supply FROM token_info_bitcoin WHERE tick = 'doge'

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE erc20_balances_historical ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.integer )
CREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )
CREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )
CREATE TABLE 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, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )
CREATE TABLE token_info ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )
CREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )
CREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )
CREATE TABLE token_activities_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE token_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] Provide the contract ID, creator address, and timestamp for all smart contracts created between January 1st, 2022, and December 31st, 2024.

[Assistant] SELECT contract_id, creator_address, timestamp FROM blockchain.smart_contracts WHERE timestamp BETWEEN '2022-01-01' AND '2024-12-31';

[User] Okay, now filter that list to only show the contracts where the code contains the word 'transfer'.

[Assistant] SELECT contract_id, creator_address, timestamp FROM blockchain.smart_contracts WHERE timestamp BETWEEN '2022-01-01' AND '2024-12-31' AND code LIKE '%transfer%';

[User] Finally, from the filtered results, I only want to see the contracts created by '0xFEDCBA9876543210FEDCBA9876543210FEDCBA98'.

[Assistant] SELECT contract_id, creator_address, timestamp FROM blockchain.smart_contracts WHERE timestamp BETWEEN '2022-01-01' AND '2024-12-31' AND code LIKE '%transfer%' AND creator_address = '0xFEDCBA9876543210FEDCBA9876543210FEDCBA98';

System:
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 )


[User] List smart money addresses, their chain, and profit for those who have incurred a loss. Order the results by the magnitude of the loss (smallest profit value first).

[Assistant] SELECT address, chain, profit FROM smart_money_profit WHERE profit < 0 ORDER BY profit ASC;

[User] From that list, show only the addresses that have a rank worse than 500 (rank number greater than 500).

[Assistant] SELECT address, chain, profit FROM smart_money_profit WHERE profit < 0 AND rank > 500 ORDER BY profit ASC;

[User] Further refine the list to include only addresses on the 'Arbitrum' chain.

[Assistant] SELECT address, chain, profit FROM smart_money_profit WHERE profit < 0 AND rank > 500 AND chain = 'Arbitrum' ORDER BY profit ASC;

[User] Based on the filtered list (loss, rank worse than 500, Arbitrum chain), what is the average profit?

[Assistant] SELECT AVG(profit) FROM smart_money_profit WHERE profit < 0 AND rank > 500 AND chain = 'Arbitrum';

System:
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_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )


[User] Show me assets along with their associated 'symbol' metadata value. Assume an assets table with asset_id exists.

[Assistant] SELECT a.asset_id, m.value FROM assets a JOIN metadata m ON a.asset_id = m.asset_id WHERE m.key = 'symbol'

[User] Now, also include the 'name' metadata value for these assets in the same result.

[Assistant] SELECT a.asset_id, m_symbol.value AS symbol, m_name.value AS name FROM assets a LEFT JOIN metadata m_symbol ON a.asset_id = m_symbol.asset_id AND m_symbol.key = 'symbol' LEFT JOIN metadata m_name ON a.asset_id = m_name.asset_id AND m_name.key = 'name'

[User] For assets that have both 'symbol' and 'name' metadata, list the asset ID and the count of *all* metadata entries they have.

[Assistant] SELECT a.asset_id, COUNT(m_all.metadata_id) FROM assets a JOIN metadata m_symbol ON a.asset_id = m_symbol.asset_id AND m_symbol.key = 'symbol' JOIN metadata m_name ON a.asset_id = m_name.asset_id AND m_name.key = 'name' JOIN metadata m_all ON a.asset_id = m_all.asset_id GROUP BY a.asset_id

System:
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 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.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )


[User] What is the total number of entries in the addresses table and the sum of all balances?

[Assistant] SELECT COUNT(*), SUM(balance) FROM blockchain.addresses;

[User] Instead of the sum, could you show me the average balance and the highest balance recorded?

[Assistant] SELECT AVG(balance), MAX(balance) FROM blockchain.addresses;

System:
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.addresses (
    address_id character varying(128) NOT NULL,  -- unique identifier for the address
    public_key text NOT NULL, -- public key associated with the address
    balance numeric(38,14) NOT NULL, -- current balance of the address
    PRIMARY KEY (address_id)
)


[User] List all distinct project names found in the fundraising records.

[Assistant] SELECT DISTINCT project_name FROM project_fundraising_record;

[User] For each project, count how many fundraising rounds are recorded.

[Assistant] SELECT project_name, COUNT(*) FROM project_fundraising_record GROUP BY project_name;

[User] Only show projects that have more than one fundraising round.

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

[User] And show the total investment value for these projects.

[Assistant] SELECT project_name, COUNT(*), SUM(investment_value) FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1;


[User] List all users and the count of wallets they own.

[Assistant] SELECT u.username, COUNT(w.wallet_id) AS wallet_count FROM blockchain.users u JOIN blockchain.wallets w ON u.user_id = w.user_id GROUP BY u.user_id, u.username;

[User] Filter the previous list to only include users who own more than 2 wallets.

[Assistant] SELECT u.username, COUNT(w.wallet_id) AS wallet_count FROM blockchain.users u JOIN blockchain.wallets w ON u.user_id = w.user_id GROUP BY u.user_id, u.username HAVING COUNT(w.wallet_id) > 2;

[User] Now, for those users, also include the total sum of balances across all addresses associated with their wallets.

[Assistant] SELECT u.username, COUNT(DISTINCT w.wallet_id) AS wallet_count, SUM(a.balance) AS total_balance FROM blockchain.users u JOIN blockchain.wallets w ON u.user_id = w.user_id JOIN blockchain.addresses a ON w.address_id = a.address_id GROUP BY u.user_id, u.username HAVING COUNT(DISTINCT w.wallet_id) > 2;

System:
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.addresses ( address_id character varying(128) NOT NULL, public_key text NOT NULL, balance numeric(38,14) NOT NULL, PRIMARY KEY (address_id) )
CREATE TABLE blockchain.nodes ( node_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (node_id) )
CREATE TABLE blockchain.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address_id character varying(128) NOT NULL, private_key text NOT NULL, PRIMARY KEY (wallet_id) )
CREATE TABLE blockchain.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, PRIMARY KEY (user_id) )


[User] List all assets that have 'category' metadata. Show the asset ID and the value of the 'category'.

[Assistant] SELECT asset_id, value AS category FROM trading_platform.metadata WHERE key = 'category';

[User] Refine this to only show assets where the 'category' is either 'Crypto' or 'Fiat'.

[Assistant] SELECT asset_id, value AS category FROM trading_platform.metadata WHERE key = 'category' AND value IN ('Crypto', 'Fiat');

[User] For each of these assets categorized as 'Crypto' or 'Fiat', how many total metadata entries (of any key) exist?

[Assistant] WITH FilteredAssets AS (SELECT asset_id FROM trading_platform.metadata WHERE key = 'category' AND value IN ('Crypto', 'Fiat')) SELECT fa.asset_id, COUNT(m.metadata_id) AS total_metadata_entries FROM FilteredAssets fa JOIN trading_platform.metadata m ON fa.asset_id = m.asset_id GROUP BY fa.asset_id;

System:
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.metadata (
    metadata_id character varying(64) NOT NULL,  -- unique identifier for the metadata
    asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
    key character varying(128) NOT NULL, -- key of the metadata
    value text NOT NULL, -- value of the metadata
    PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.notifications (
    notification_id character varying(64) NOT NULL,  -- unique identifier for the notification
    user_id character varying(64) NOT NULL, -- identifier of the user receiving the notification
    message text NOT NULL, -- message of the notification
    sent_at timestamp NOT NULL, -- time when the notification was sent
    read_at timestamp, -- time when the notification was read
    PRIMARY KEY (notification_id)
)


[User] Show the symbol and current balance for all ERC20 tokens held by wallet '0x...abc'.

[Assistant] SELECT T2.symbol, T1.amount FROM erc20_balances AS T1 INNER JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address WHERE T1.wallet_address = '0x...abc' AND T2.is_erc20 = 1;

[User] Filter the results to only include tokens where the balance exceeds a certain amount, say '1000000000000000000'.

[Assistant] SELECT T2.symbol, T1.amount FROM erc20_balances AS T1 INNER JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address WHERE T1.wallet_address = '0x...abc' AND T2.is_erc20 = 1 AND T1.amount > '1000000000000000000';

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )
CREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )
CREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )
CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )
CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )
CREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )
CREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )
CREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )
CREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )
CREATE TABLE token_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_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )
CREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )
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 me tokens that have recorded smart money inflows. For these tokens, list the token symbol, the current price from the basic info table, and the total sum of USD values from all smart money inflows recorded for that token.

[Assistant] SELECT tbi.token_symbol, tbi.price, SUM(smti.usd_value) FROM token_basic_info tbi JOIN smart_money_token_inflow smti ON tbi.token_address = smti.token_address GROUP BY tbi.token_symbol, tbi.price;

System:
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 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_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] Display the details of all UTXOs with a 'spent' status of false.

[Assistant] SELECT utxo_id, transaction_id, output_index, address, amount FROM trading_platform.utxos WHERE spent = false;

[User] For the unspent UTXOs, calculate the sum of amounts for each distinct address.

[Assistant] SELECT address, SUM(amount) FROM trading_platform.utxos WHERE spent = false GROUP BY address;

[User] Filter this list to only show addresses where the total unspent amount is greater than 1000.

[Assistant] SELECT address, SUM(amount) FROM trading_platform.utxos WHERE spent = false GROUP BY address HAVING SUM(amount) > 1000;

System:
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.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
CREATE TABLE trading_platform.assets ( asset_id text, 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.peers ( peer_id text, ip_address text, port integer, last_seen timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id text, asset_id text, key text, value text )
CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )


[User] What are the latest prices for tokens with symbol 'USDT'?

[Assistant] SELECT * FROM token_prices_latest WHERE symbol = 'USDT';

[User] Now show me the historical prices for 'USDT' from the last 7 days.

[Assistant] SELECT * FROM token_prices WHERE symbol = 'USDT' AND timestamp >= CURRENT_TIMESTAMP - INTERVAL '7' DAY;

System:
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, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )
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 varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )
CREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )
CREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )
CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )
CREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )
CREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )
CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )
CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )
CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )
CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
CREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )
CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )
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 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] Provide a list of node IDs, IP addresses, and the contract IDs and timestamps of smart contracts that were hypothetically created by these nodes.

[Assistant] SELECT T1.node_id, T1.ip_address, T2.contract_id, T2.timestamp FROM blockchain.nodes AS T1 JOIN blockchain.smart_contracts AS T2 ON T1.node_id = T2.creator_address;

[User] Add the node's port number to the results.

[Assistant] SELECT T1.node_id, T1.ip_address, T1.port, T2.contract_id, T2.timestamp FROM blockchain.nodes AS T1 JOIN blockchain.smart_contracts AS T2 ON T1.node_id = T2.creator_address;

[User] Filter this list to only include contracts created after January 1st, 2024.

[Assistant] SELECT T1.node_id, T1.ip_address, T1.port, T2.contract_id, T2.timestamp FROM blockchain.nodes AS T1 JOIN blockchain.smart_contracts AS T2 ON T1.node_id = T2.creator_address WHERE T2.timestamp > '2024-01-01';

System:
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.nodes (
    node_id character varying(64) NOT NULL,  -- unique identifier for the node
    ip_address character varying(15) NOT NULL, -- IP address of the node
    port integer NOT NULL, -- port number of the node
    last_seen timestamp NOT NULL, -- last time the node was active
    PRIMARY KEY (node_id)
)
CREATE TABLE blockchain.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
    PRIMARY KEY (user_id)
)
CREATE TABLE blockchain.smart_contracts (
    contract_id character varying(64) NOT NULL,  -- unique identifier for the smart contract
    creator_address character varying(128) NOT NULL, -- address of the creator of the contract
    code text NOT NULL, -- code of the smart contract
    timestamp timestamp NOT NULL, -- time when the contract was deployed
    PRIMARY KEY (contract_id)
)


[User] Show me all contract addresses deployed by the address '0xabc...def'.

[Assistant] SELECT address FROM web3.contracts WHERE deployer_address = '0xabc...def';

[User] Can you refine that list to only include contracts that are currently 'active'?

[Assistant] SELECT address FROM web3.contracts WHERE deployer_address = '0xabc...def' AND status = 'active';

[User] Further filter it to only show those deployed between '2023-01-01' and '2023-12-31'.

[Assistant] SELECT address FROM web3.contracts WHERE deployer_address = '0xabc...def' AND status = 'active' AND deployed_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Instead of listing addresses, please count how many such contracts exist for this deployer, grouped by the network they are deployed on.

[Assistant] SELECT network_id, COUNT(*) FROM web3.contracts WHERE deployer_address = '0xabc...def' AND status = 'active' AND deployed_at BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY network_id;

System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts ( contract_id text PRIMARY KEY, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )