Dataset Viewer
Auto-converted to Parquet Duplicate
system
stringlengths
315
8.06k
conversations
listlengths
2
48
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )
[ { "role": "user", "content": "For each server, what is the earliest and latest start time of its sessions?", "sql": null }, { "role": "assistant", "content": "SELECT server_id, MIN(start_time), MAX(start_time) FROM gaming_technology.game_sessions GROUP BY server_id;", "sql": null }, { "role": "user", "content": "Only show servers where the difference between the earliest and latest session is more than 30 days.", "sql": null }, { "role": "assistant", "content": "SELECT server_id, MIN(start_time), MAX(start_time) FROM gaming_technology.game_sessions GROUP BY server_id HAVING MAX(start_time) - MIN(start_time) > INTERVAL '30 days';", "sql": null }, { "role": "user", "content": "Show each player's highest score for each game they have played.", "sql": null }, { "role": "assistant", "content": "SELECT player_id, game_id, MAX(score) AS highest_score FROM gaming_technology.game_sessions GROUP BY player_id, game_id;", "sql": null }, { "role": "user", "content": "Only include games where the player's highest score is at least 500.", "sql": null }, { "role": "assistant", "content": "SELECT player_id, game_id, MAX(score) AS highest_score FROM gaming_technology.game_sessions GROUP BY player_id, game_id HAVING MAX(score) >= 500;", "sql": null }, { "role": "user", "content": "For each result, could you also include the number of sessions that player has for that game?", "sql": null }, { "role": "assistant", "content": "SELECT player_id, game_id, COUNT(*) AS session_count, MAX(score) AS highest_score FROM gaming_technology.game_sessions GROUP BY player_id, game_id HAVING MAX(score) >= 500;", "sql": null }, { "role": "user", "content": "Order the results by highest_score in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT player_id, game_id, COUNT(*) AS session_count, MAX(score) AS highest_score FROM gaming_technology.game_sessions GROUP BY player_id, game_id HAVING MAX(score) >= 500 ORDER BY highest_score DESC;", "sql": null }, { "role": "user", "content": "Show the total session duration in seconds and the average score for each game.", "sql": null }, { "role": "assistant", "content": "SELECT game_id, SUM(duration_seconds), AVG(score) FROM gaming_technology.game_sessions GROUP BY game_id;", "sql": null }, { "role": "user", "content": "Now, only include games where the total session duration is greater than 100000 seconds.", "sql": null }, { "role": "assistant", "content": "SELECT game_id, SUM(duration_seconds), AVG(score) FROM gaming_technology.game_sessions GROUP BY game_id HAVING SUM(duration_seconds) > 100000;", "sql": null }, { "role": "user", "content": "How many game sessions started on each calendar day?", "sql": null }, { "role": "assistant", "content": "SELECT DATE(start_time), COUNT(*) FROM gaming_technology.game_sessions GROUP BY DATE(start_time) ORDER BY DATE(start_time);", "sql": null }, { "role": "user", "content": "Only display days that had more than 100 sessions.", "sql": null }, { "role": "assistant", "content": "SELECT DATE(start_time), COUNT(*) FROM gaming_technology.game_sessions GROUP BY DATE(start_time) HAVING COUNT(*) > 100 ORDER BY DATE(start_time);", "sql": null }, { "role": "user", "content": "Can you show me the total number of sessions and the average score for each server and each game combination?", "sql": null }, { "role": "assistant", "content": "SELECT server_id, game_id, COUNT(*) AS total_sessions, AVG(score) AS average_score FROM gaming_technology.game_sessions GROUP BY server_id, game_id;", "sql": null }, { "role": "user", "content": "Could you filter this to only include combinations where the average score is above 200?", "sql": null }, { "role": "assistant", "content": "SELECT server_id, game_id, COUNT(*) AS total_sessions, AVG(score) AS average_score FROM gaming_technology.game_sessions GROUP BY server_id, game_id HAVING AVG(score) > 200;", "sql": null }, { "role": "user", "content": "Can you add the total duration in seconds for each combination as well?", "sql": null }, { "role": "assistant", "content": "SELECT server_id, game_id, COUNT(*) AS total_sessions, AVG(score) AS average_score, SUM(duration_seconds) AS total_duration FROM gaming_technology.game_sessions GROUP BY server_id, game_id HAVING AVG(score) > 200;", "sql": null }, { "role": "user", "content": "Now, only show combinations where the total duration exceeds 10,000 seconds.", "sql": null }, { "role": "assistant", "content": "SELECT server_id, game_id, COUNT(*) AS total_sessions, AVG(score) AS average_score, SUM(duration_seconds) AS total_duration FROM gaming_technology.game_sessions GROUP BY server_id, game_id HAVING AVG(score) > 200 AND SUM(duration_seconds) > 10000;", "sql": null }, { "role": "user", "content": "Show the game ID and the average session duration in minutes for each game, ordered by average session duration descending.", "sql": null }, { "role": "assistant", "content": "SELECT game_id, AVG(duration_seconds) / 60.0 AS avg_duration_minutes\nFROM gaming_technology.game_sessions\nGROUP BY game_id\nORDER BY avg_duration_minutes DESC;", "sql": null }, { "role": "user", "content": "Also, include the total number of sessions for each game.", "sql": null }, { "role": "assistant", "content": "SELECT game_id, COUNT(*) AS total_sessions, AVG(duration_seconds) / 60.0 AS avg_duration_minutes\nFROM gaming_technology.game_sessions\nGROUP BY game_id\nORDER BY avg_duration_minutes DESC;", "sql": null }, { "role": "user", "content": "Filter to only show games with at least 100 sessions.", "sql": null }, { "role": "assistant", "content": "SELECT game_id, COUNT(*) AS total_sessions, AVG(duration_seconds) / 60.0 AS avg_duration_minutes\nFROM gaming_technology.game_sessions\nGROUP BY game_id\nHAVING COUNT(*) >= 100\nORDER BY avg_duration_minutes DESC;", "sql": null }, { "role": "user", "content": "Order by total_sessions descending, then avg_duration_minutes descending.", "sql": null }, { "role": "assistant", "content": "SELECT game_id, COUNT(*) AS total_sessions, AVG(duration_seconds) / 60.0 AS avg_duration_minutes\nFROM gaming_technology.game_sessions\nGROUP BY game_id\nHAVING COUNT(*) >= 100\nORDER BY total_sessions DESC, avg_duration_minutes DESC;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric ) CREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric ) CREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric ) CREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text ) CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )
[ { "role": "user", "content": "Which exchange holds the largest total USD value of the token with the highest 24h price increase in the 'AI' narrative, and what is that value?", "sql": null }, { "role": "assistant", "content": "SELECT ctb.exchange, SUM(ctb.usd_value) AS total_usd_value\nFROM token_basic_info tbi\nJOIN cex_token_balance ctb ON tbi.token_address = ctb.token_address AND tbi.chain = ctb.chain\nWHERE tbi.narrative = 'AI' AND tbi.token_symbol = (\n SELECT token_symbol\n FROM token_basic_info\n WHERE narrative = 'AI'\n ORDER BY price_change_percentage_24h DESC\n LIMIT 1\n)\nGROUP BY ctb.exchange\nORDER BY total_usd_value DESC\nLIMIT 1;", "sql": null }, { "role": "user", "content": "Actually, can you show the top 2 exchanges by total USD value instead of just the top one?", "sql": null }, { "role": "assistant", "content": "SELECT ctb.exchange, SUM(ctb.usd_value) AS total_usd_value\nFROM token_basic_info tbi\nJOIN cex_token_balance ctb ON tbi.token_address = ctb.token_address AND tbi.chain = ctb.chain\nWHERE tbi.narrative = 'AI' AND tbi.token_symbol = (\n SELECT token_symbol\n FROM token_basic_info\n WHERE narrative = 'AI'\n ORDER BY price_change_percentage_24h DESC\n LIMIT 1\n)\nGROUP BY ctb.exchange\nORDER BY total_usd_value DESC\nLIMIT 2;", "sql": null }, { "role": "user", "content": "Great, now also include the chain and current price of this token in the results.", "sql": null }, { "role": "assistant", "content": "SELECT ctb.exchange, ctb.chain, SUM(ctb.usd_value) AS total_usd_value, tbi.price\nFROM token_basic_info tbi\nJOIN cex_token_balance ctb ON tbi.token_address = ctb.token_address AND tbi.chain = ctb.chain\nWHERE tbi.narrative = 'AI' AND tbi.token_symbol = (\n SELECT token_symbol\n FROM token_basic_info\n WHERE narrative = 'AI'\n ORDER BY price_change_percentage_24h DESC\n LIMIT 1\n)\nGROUP BY ctb.exchange, ctb.chain, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 2;", "sql": null }, { "role": "user", "content": "Which are the top 3 tokens on BSC by total USD value held by all CEXs, and what is their narrative and current price?", "sql": null }, { "role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 3;", "sql": null }, { "role": "user", "content": "Can you also show, for each token, the number of CEX addresses holding it?", "sql": null }, { "role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, COUNT(DISTINCT ctb.address) AS cex_address_count, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 3;", "sql": null }, { "role": "user", "content": "Only include tokens with total USD value above 1,000,000.", "sql": null }, { "role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, COUNT(DISTINCT ctb.address) AS cex_address_count, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nHAVING SUM(ctb.usd_value) > 1000000\nORDER BY total_usd_value DESC\nLIMIT 3;", "sql": null }, { "role": "user", "content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?", "sql": null }, { "role": "assistant", "content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;", "sql": null }, { "role": "user", "content": "What is the average ROI for smart money addresses on the Binance chain?", "sql": null }, { "role": "assistant", "content": "SELECT AVG(roi) FROM smart_money_profit WHERE chain = 'Binance';", "sql": null }, { "role": "user", "content": "Show me tokens with a 24-hour trading volume over $1,000,000 from DEX pools that also have a positive net flow from smart money addresses. Display the token symbol, chain, 24h volume, and net flow.", "sql": null }, { "role": "assistant", "content": "SELECT tdi.token_symbol, tdi.chain, tdi.volume_24h, smtp.net_flow FROM token_dexpool_info AS tdi JOIN smart_money_token_performance AS smtp ON tdi.token_symbol = smtp.token_symbol AND tdi.chain = smtp.chain WHERE tdi.volume_24h > 1000000 AND smtp.net_flow > 0;", "sql": null }, { "role": "user", "content": "Okay, now refine the results to only include tokens where the smart money ROI is greater than 5 (500%) and the realized ratio is above 0.5.", "sql": null }, { "role": "assistant", "content": "SELECT tdi.token_symbol, tdi.chain, tdi.volume_24h, smtp.net_flow FROM token_dexpool_info AS tdi JOIN smart_money_token_performance AS smtp ON tdi.token_symbol = smtp.token_symbol AND tdi.chain = smtp.chain WHERE tdi.volume_24h > 1000000 AND smtp.net_flow > 0 AND smtp.roi > 5 AND smtp.realized_ratio > 0.5;", "sql": null }, { "role": "user", "content": "Add the token's current price from the basic info table and its narrative category to the results.", "sql": null }, { "role": "assistant", "content": "SELECT tdi.token_symbol, tdi.chain, tdi.volume_24h, smtp.net_flow, tbi.price AS current_price, tbi.narrative FROM token_dexpool_info AS tdi JOIN smart_money_token_performance AS smtp ON tdi.token_symbol = smtp.token_symbol AND tdi.chain = smtp.chain JOIN token_basic_info AS tbi ON tdi.token_symbol = tbi.token_symbol AND tdi.chain = tbi.chain WHERE tdi.volume_24h > 1000000 AND smtp.net_flow > 0 AND smtp.roi > 5 AND smtp.realized_ratio > 0.5;", "sql": null }, { "role": "user", "content": "Order the final list by 24-hour trading volume descending and show the top 10.", "sql": null }, { "role": "assistant", "content": "SELECT tdi.token_symbol, tdi.chain, tdi.volume_24h, smtp.net_flow, tbi.price AS current_price, tbi.narrative FROM token_dexpool_info AS tdi JOIN smart_money_token_performance AS smtp ON tdi.token_symbol = smtp.token_symbol AND tdi.chain = smtp.chain JOIN token_basic_info AS tbi ON tdi.token_symbol = tbi.token_symbol AND tdi.chain = tbi.chain WHERE tdi.volume_24h > 1000000 AND smtp.net_flow > 0 AND smtp.roi > 5 AND smtp.realized_ratio > 0.5 ORDER BY tdi.volume_24h DESC LIMIT 10;", "sql": null }, { "role": "user", "content": "List tokens that have a price increase of more than 10% in the last 24 hours and belong to a narrative with a trend rank of 10 or better. For these tokens, show their symbol, chain, 24h price change, the narrative, and the narrative's trend rank.", "sql": null }, { "role": "assistant", "content": "SELECT T1.token_symbol, T1.chain, T1.price_change_percentage_24h, T1.narrative, T2.trend_rank FROM token_basic_info AS T1 INNER JOIN narrative_info AS T2 ON T1.narrative = T2.narrative WHERE T1.price_change_percentage_24h > 10 AND T2.trend_rank <= 10;", "sql": null }, { "role": "user", "content": "Now, for these same tokens, include their smart money Net Flow and ROI.", "sql": null }, { "role": "assistant", "content": "SELECT T1.token_symbol, T1.chain, T1.price_change_percentage_24h, T1.narrative, T2.trend_rank, T3.net_flow, T3.roi FROM token_basic_info AS T1 INNER JOIN narrative_info AS T2 ON T1.narrative = T2.narrative INNER JOIN smart_money_token_performance AS T3 ON T1.token_symbol = T3.token_symbol AND T1.chain = T3.chain WHERE T1.price_change_percentage_24h > 10 AND T2.trend_rank <= 10;", "sql": null }, { "role": "user", "content": "Filter the results to only include tokens where the Smart Money Net Flow is greater than 10000 and the ROI is greater than 2.", "sql": null }, { "role": "assistant", "content": "SELECT T1.token_symbol, T1.chain, T1.price_change_percentage_24h, T1.narrative, T2.trend_rank, T3.net_flow, T3.roi FROM token_basic_info AS T1 INNER JOIN narrative_info AS T2 ON T1.narrative = T2.narrative INNER JOIN smart_money_token_performance AS T3 ON T1.token_symbol = T3.token_symbol AND T1.chain = T3.chain WHERE T1.price_change_percentage_24h > 10 AND T2.trend_rank <= 10 AND T3.net_flow > 10000 AND T3.roi > 2;", "sql": null }, { "role": "user", "content": "Order the results by Smart Money Net Flow in descending order and show the top 5.", "sql": null }, { "role": "assistant", "content": "SELECT T1.token_symbol, T1.chain, T1.price_change_percentage_24h, T1.narrative, T2.trend_rank, T3.net_flow, T3.roi FROM token_basic_info AS T1 INNER JOIN narrative_info AS T2 ON T1.narrative = T2.narrative INNER JOIN smart_money_token_performance AS T3 ON T1.token_symbol = T3.token_symbol AND T1.chain = T3.chain WHERE T1.price_change_percentage_24h > 10 AND T2.trend_rank <= 10 AND T3.net_flow > 10000 AND T3.roi > 2 ORDER BY T3.net_flow DESC LIMIT 5;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE financial_services.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address text NOT NULL, city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status character varying(32) NOT NULL, risk_profile character varying(50), PRIMARY KEY (customer_id) ) CREATE TABLE financial_services.transactions ( transaction_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, related_account_id character varying(64), transaction_type character varying(50) NOT NULL, amount numeric(19, 4) NOT NULL, currency character varying(3) NOT NULL, transaction_date timestamp NOT NULL, effective_date date NOT NULL, description text, status character varying(32) NOT NULL, reference_number character varying(128), PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) ) CREATE TABLE financial_services.securities ( security_id character varying(64) NOT NULL, ticker_symbol character varying(20) NOT NULL UNIQUE, isin_code character varying(12) UNIQUE, cusip_code character varying(9) UNIQUE, security_name text NOT NULL, security_type character varying(50) NOT NULL, exchange character varying(50), currency character varying(3) NOT NULL, issuer_name character varying(255), sector character varying(100), last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (security_id) ) CREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) ) CREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )
[ { "role": "user", "content": "List all customers and the total amount they have traded, showing their full name, email, and the total across all their trades. Join customers to their accounts, then to trades.", "sql": null }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, c.email, SUM(t.total_amount) AS total_trade_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email;", "sql": null }, { "role": "user", "content": "Please include only trades with a status of 'EXECUTED' in the calculation.", "sql": null }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, c.email, SUM(t.total_amount) AS total_trade_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nWHERE t.status = 'EXECUTED'\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email;", "sql": null }, { "role": "user", "content": "Only show customers whose total_trade_amount is greater than 5000.", "sql": null }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, c.email, SUM(t.total_amount) AS total_trade_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nWHERE t.status = 'EXECUTED'\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email\nHAVING SUM(t.total_amount) > 5000;", "sql": null }, { "role": "user", "content": "Sort the result by total_trade_amount in descending order and limit to the first 10 results.", "sql": null }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, c.email, SUM(t.total_amount) AS total_trade_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nWHERE t.status = 'EXECUTED'\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email\nHAVING SUM(t.total_amount) > 5000\nORDER BY total_trade_amount DESC\nLIMIT 10;", "sql": null }, { "role": "user", "content": "List each security and the total amount traded for it, with ticker symbol and security name. Only include trades from the last 90 days.", "sql": null }, { "role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, SUM(t.total_amount) AS total_traded_amount\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= NOW() - INTERVAL '90 days'\nGROUP BY s.ticker_symbol, s.security_name;", "sql": null }, { "role": "user", "content": "Also include the number of distinct accounts involved in trades for each security during this period.", "sql": null }, { "role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, SUM(t.total_amount) AS total_traded_amount, COUNT(DISTINCT t.account_id) AS account_count\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= NOW() - INTERVAL '90 days'\nGROUP BY s.ticker_symbol, s.security_name;", "sql": null }, { "role": "user", "content": "Only display securities where the account_count is greater than 5, and sort by total_traded_amount descending.", "sql": null }, { "role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, SUM(t.total_amount) AS total_traded_amount, COUNT(DISTINCT t.account_id) AS account_count\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= NOW() - INTERVAL '90 days'\nGROUP BY s.ticker_symbol, s.security_name\nHAVING COUNT(DISTINCT t.account_id) > 5\nORDER BY total_traded_amount DESC;", "sql": null }, { "role": "user", "content": "I need a summary of total traded volume and average price per unit by sector using the trades and securities tables for trades in the last 30 days.", "sql": null }, { "role": "assistant", "content": "SELECT\n s.sector,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price_per_unit\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30 days'\nGROUP BY s.sector;", "sql": null }, { "role": "user", "content": "Only include sectors where the summed quantity is at least 1000.", "sql": null }, { "role": "assistant", "content": "SELECT\n s.sector,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price_per_unit\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30 days'\nGROUP BY s.sector\nHAVING SUM(t.quantity) >= 1000;", "sql": null }, { "role": "user", "content": "Sort the result by average price per unit ascending.", "sql": null }, { "role": "assistant", "content": "SELECT\n s.sector,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price_per_unit\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30 days'\nGROUP BY s.sector\nHAVING SUM(t.quantity) >= 1000\nORDER BY avg_price_per_unit ASC;", "sql": null }, { "role": "user", "content": "Also ensure sectors are not null.", "sql": null }, { "role": "assistant", "content": "SELECT\n s.sector,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price_per_unit\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30 days'\n AND s.sector IS NOT NULL\nGROUP BY s.sector\nHAVING SUM(t.quantity) >= 1000\nORDER BY avg_price_per_unit ASC;", "sql": null }, { "role": "user", "content": "Show me all loans with matching collateral, displaying loan_id, principal_amount, the collateral ticker, and its sector.", "sql": null }, { "role": "assistant", "content": "SELECT\n l.loan_id,\n l.principal_amount,\n s.ticker_symbol,\n s.sector\nFROM financial_services.loans l\nJOIN financial_services.securities s\n ON l.collateral_description = s.ticker_symbol;", "sql": null }, { "role": "user", "content": "Filter this to loans with status 'Active' and securities of type 'Bond'.", "sql": null }, { "role": "assistant", "content": "SELECT\n l.loan_id,\n l.principal_amount,\n s.ticker_symbol,\n s.sector\nFROM financial_services.loans l\nJOIN financial_services.securities s\n ON l.collateral_description = s.ticker_symbol\nWHERE l.status = 'Active'\n AND s.security_type = 'Bond';", "sql": null }, { "role": "user", "content": "Finally, sort by maturity_date ascending and limit the result to the first 10 rows.", "sql": null }, { "role": "assistant", "content": "SELECT\n l.loan_id,\n l.principal_amount,\n s.ticker_symbol,\n s.sector\nFROM financial_services.loans l\nJOIN financial_services.securities s\n ON l.collateral_description = s.ticker_symbol\nWHERE l.status = 'Active'\n AND s.security_type = 'Bond'\nORDER BY l.maturity_date ASC\nLIMIT 10;", "sql": null }, { "role": "user", "content": "List each employee and their manager's full name, showing employee_id, employee full name, and manager full name.", "sql": null }, { "role": "assistant", "content": "SELECT\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_name,\n m.first_name || ' ' || m.last_name AS manager_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;", "sql": null }, { "role": "user", "content": "Only include active employees and exclude those without a manager.", "sql": null }, { "role": "assistant", "content": "SELECT\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_name,\n m.first_name || ' ' || m.last_name AS manager_name\nFROM financial_services.employees e\nJOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.status = 'Active'\n AND e.manager_id IS NOT NULL;", "sql": null }, { "role": "user", "content": "Now sort the output by department ascending and then by employee_name ascending.", "sql": null }, { "role": "assistant", "content": "SELECT\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_name,\n m.first_name || ' ' || m.last_name AS manager_name\nFROM financial_services.employees e\nJOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.status = 'Active'\n AND e.manager_id IS NOT NULL\nORDER BY e.department ASC, employee_name ASC;", "sql": null }, { "role": "user", "content": "Summarize the total principal amount for loans, grouped by customer and their account type. Include the customer's full name.", "sql": null }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.account_type, SUM(T3.principal_amount) FROM financial_services.customers AS T1 JOIN financial_services.accounts AS T2 ON T1.customer_id = T2.customer_id JOIN financial_services.loans AS T3 ON T2.account_id = T3.account_id GROUP BY T1.customer_id, T1.first_name, T1.last_name, T2.account_type;", "sql": null }, { "role": "user", "content": "Only include accounts and loans that are currently 'Active'.", "sql": null }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.account_type, SUM(T3.principal_amount) FROM financial_services.customers AS T1 JOIN financial_services.accounts AS T2 ON T1.customer_id = T2.customer_id JOIN financial_services.loans AS T3 ON T2.account_id = T3.account_id WHERE T2.status = 'Active' AND T3.status = 'Active' GROUP BY T1.customer_id, T1.first_name, T1.last_name, T2.account_type;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE blockchain.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer ) 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.addresses ( address_id text, public_key text, balance numeric ) CREATE TABLE blockchain.wallets ( wallet_id text, user_id text, address_id text, private_key text )
[ { "role": "user", "content": "List the block_id, timestamp, and the total amount of transactions for each block, along with the sender and receiver addresses for each transaction that occurred on April 10th, 2023.", "sql": null }, { "role": "assistant", "content": "SELECT b.block_id, b.timestamp, t.sender_address, t.receiver_address, SUM(t.amount) as total_amount_in_block\nFROM blockchain.blocks b\nJOIN blockchain.transactions t ON b.block_id = t.block_id\nWHERE DATE(t.timestamp) = '2023-04-10'\nGROUP BY b.block_id, b.timestamp, t.sender_address, t.receiver_address;", "sql": null }, { "role": "user", "content": "Can you also include the balance of both sender and receiver addresses at the time of the transaction?", "sql": null }, { "role": "assistant", "content": "SELECT b.block_id, b.timestamp, t.sender_address, sa.balance AS sender_balance, t.receiver_address, ra.balance AS receiver_balance, SUM(t.amount) as total_amount_in_block\nFROM blockchain.blocks b\nJOIN blockchain.transactions t ON b.block_id = t.block_id\nLEFT JOIN blockchain.addresses sa ON t.sender_address = sa.address_id\nLEFT JOIN blockchain.addresses ra ON t.receiver_address = ra.address_id\nWHERE DATE(t.timestamp) = '2023-04-10'\nGROUP BY b.block_id, b.timestamp, t.sender_address, sa.balance, t.receiver_address, ra.balance;", "sql": null }, { "role": "user", "content": "Now only show those transactions where the sender's balance was greater than 5000 at that time.", "sql": null }, { "role": "assistant", "content": "SELECT b.block_id, b.timestamp, t.sender_address, sa.balance AS sender_balance, t.receiver_address, ra.balance AS receiver_balance, SUM(t.amount) as total_amount_in_block\nFROM blockchain.blocks b\nJOIN blockchain.transactions t ON b.block_id = t.block_id\nLEFT JOIN blockchain.addresses sa ON t.sender_address = sa.address_id\nLEFT JOIN blockchain.addresses ra ON t.receiver_address = ra.address_id\nWHERE DATE(t.timestamp) = '2023-04-10' AND sa.balance > 5000\nGROUP BY b.block_id, b.timestamp, t.sender_address, sa.balance, t.receiver_address, ra.balance;", "sql": null }, { "role": "user", "content": "Sorry, the sender_address seems incorrect. Use sender_address from transactions table instead of addresses.", "sql": null }, { "role": "assistant", "content": "SELECT b.block_id, b.timestamp, t.sender_address, sa.balance AS sender_balance, t.receiver_address, ra.balance AS receiver_balance, SUM(t.amount) as total_amount_in_block\nFROM blockchain.blocks b\nJOIN blockchain.transactions t ON b.block_id = t.block_id\nLEFT JOIN blockchain.addresses sa ON t.sender_address = sa.address_id\nLEFT JOIN blockchain.addresses ra ON t.receiver_address = ra.address_id\nWHERE DATE(t.timestamp) = '2023-04-10' AND sa.balance > 5000\nGROUP BY b.block_id, b.timestamp, t.sender_address, sa.balance, t.receiver_address, ra.balance;", "sql": null }, { "role": "user", "content": "Show me each transaction with its ID, amount, timestamp, and the usernames of both sender and receiver.", "sql": null }, { "role": "assistant", "content": "SELECT t.transaction_id, t.amount, t.timestamp, us.username AS sender_username, ur.username AS receiver_username\nFROM blockchain.transactions t\nLEFT JOIN blockchain.wallets ws ON t.sender_address = ws.address_id\nLEFT JOIN blockchain.users us ON ws.user_id = us.user_id\nLEFT JOIN blockchain.wallets wr ON t.receiver_address = wr.address_id\nLEFT JOIN blockchain.users ur ON wr.user_id = ur.user_id;", "sql": null }, { "role": "user", "content": "List all address IDs with a balance under 50, along with the count of transactions they have received.", "sql": null }, { "role": "assistant", "content": "SELECT a.address_id, a.balance, COUNT(t.transaction_id) AS received_count\nFROM blockchain.addresses a\nLEFT JOIN blockchain.transactions t ON a.address_id = t.receiver_address\nWHERE a.balance < 50\nGROUP BY a.address_id, a.balance;", "sql": null }, { "role": "user", "content": "Now only include addresses that have received at least 5 transactions.", "sql": null }, { "role": "assistant", "content": "SELECT a.address_id, a.balance, COUNT(t.transaction_id) AS received_count\nFROM blockchain.addresses a\nLEFT JOIN blockchain.transactions t ON a.address_id = t.receiver_address\nWHERE a.balance < 50\nGROUP BY a.address_id, a.balance\nHAVING COUNT(t.transaction_id) >= 5;", "sql": null }, { "role": "user", "content": "Also include the latest transaction timestamp for each address.", "sql": null }, { "role": "assistant", "content": "SELECT a.address_id, a.balance, COUNT(t.transaction_id) AS received_count, MAX(t.timestamp) AS last_received\nFROM blockchain.addresses a\nLEFT JOIN blockchain.transactions t ON a.address_id = t.receiver_address\nWHERE a.balance < 50\nGROUP BY a.address_id, a.balance\nHAVING COUNT(t.transaction_id) >= 5;", "sql": null }, { "role": "user", "content": "I need to list each user’s ID, email, and the total amount they've sent in transactions.", "sql": null }, { "role": "assistant", "content": "SELECT u.user_id, u.email, COALESCE(SUM(t.amount), 0) AS total_sent\nFROM blockchain.users u\nJOIN blockchain.wallets w ON u.user_id = w.user_id\nJOIN blockchain.transactions t ON w.address_id = t.sender_address\nGROUP BY u.user_id, u.email;", "sql": null }, { "role": "user", "content": "Actually, I'd like to filter only those users who have sent more than 10000 in total.", "sql": null }, { "role": "assistant", "content": "SELECT u.user_id, u.email, SUM(t.amount) AS total_sent\nFROM blockchain.users u\nJOIN blockchain.wallets w ON u.user_id = w.user_id\nJOIN blockchain.transactions t ON w.address_id = t.sender_address\nGROUP BY u.user_id, u.email\nHAVING SUM(t.amount) > 10000;", "sql": null }, { "role": "user", "content": "Can you also include the average transaction amount per user?", "sql": null }, { "role": "assistant", "content": "SELECT u.user_id, u.email, SUM(t.amount) AS total_sent, AVG(t.amount) AS avg_sent\nFROM blockchain.users u\nJOIN blockchain.wallets w ON u.user_id = w.user_id\nJOIN blockchain.transactions t ON w.address_id = t.sender_address\nGROUP BY u.user_id, u.email\nHAVING SUM(t.amount) > 10000;", "sql": null }, { "role": "user", "content": "One more thing: restrict this to transactions from the last 30 days and order by total_sent descending.", "sql": null }, { "role": "assistant", "content": "SELECT u.user_id, u.email, SUM(t.amount) AS total_sent, AVG(t.amount) AS avg_sent\nFROM blockchain.users u\nJOIN blockchain.wallets w ON u.user_id = w.user_id\nJOIN blockchain.transactions t ON w.address_id = t.sender_address\nWHERE t.timestamp >= current_date - INTERVAL '30 days'\nGROUP BY u.user_id, u.email\nHAVING SUM(t.amount) > 10000\nORDER BY total_sent DESC;", "sql": null }, { "role": "user", "content": "Find all blocks where the difficulty is between 1000 and 2000.", "sql": null }, { "role": "assistant", "content": "SELECT * FROM blockchain.blocks WHERE difficulty BETWEEN 1000 AND 2000;", "sql": null }, { "role": "user", "content": "Now filter these results to only show blocks mined after June 1, 2023.", "sql": null }, { "role": "assistant", "content": "SELECT * FROM blockchain.blocks WHERE difficulty BETWEEN 1000 AND 2000 AND timestamp > '2023-06-01';", "sql": null }, { "role": "user", "content": "Actually, I want to see the count of such blocks grouped by month in 2023.", "sql": null }, { "role": "assistant", "content": "SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count\nFROM blockchain.blocks\nWHERE difficulty BETWEEN 1000 AND 2000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31'\nGROUP BY month\nORDER BY month;", "sql": null }, { "role": "user", "content": "Can you also include the average difficulty for each month in the results?", "sql": null }, { "role": "assistant", "content": "SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count, AVG(difficulty) AS avg_difficulty\nFROM blockchain.blocks\nWHERE difficulty BETWEEN 1000 AND 2000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31'\nGROUP BY month\nORDER BY month;", "sql": null }, { "role": "user", "content": "Show me the block with the earliest timestamp and its corresponding previous block's difficulty level.", "sql": null }, { "role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b2.difficulty AS previous_block_difficulty\nFROM blockchain.blocks b1\nLEFT JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id\nORDER BY b1.timestamp ASC\nLIMIT 1;", "sql": null }, { "role": "user", "content": "Now show me the same information but for the 5 earliest blocks instead of just one.", "sql": null }, { "role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b2.difficulty AS previous_block_difficulty\nFROM blockchain.blocks b1\nLEFT JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id\nORDER BY b1.timestamp ASC\nLIMIT 5;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE 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 erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar ) CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer ) 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 sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar ) CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar ) CREATE TABLE nft_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 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_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 )
[ { "role": "user", "content": "Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens where the price is greater than $0.1.", "sql": null }, { "role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;", "sql": null }, { "role": "user", "content": "I think there's an error in your query - it should be 'tpl.symbol' not 'tm.symbol'. Also, can you add the decimals to the results?", "sql": null }, { "role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.decimals, tm.total_supply, tpl.symbol, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;", "sql": null }, { "role": "user", "content": "Now filter these results to only show tokens with decimals equal to 18.", "sql": null }, { "role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.decimals, tm.total_supply, tpl.symbol, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.1 AND tm.decimals = 18 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;", "sql": null }, { "role": "user", "content": "Find the contract address and name for all NFT collections listed on the 'Ethereum' blockchain.", "sql": null }, { "role": "assistant", "content": "SELECT contract_address, name FROM nft_collections WHERE blockchain = 'Ethereum'", "sql": null }, { "role": "user", "content": "For these collections, can you show the count of unique wallet addresses holding NFTs in each collection by joining with nft_holders?", "sql": null }, { "role": "assistant", "content": "SELECT T1.contract_address, T1.name, COUNT(DISTINCT T2.wallet_address) AS unique_holder_count FROM nft_collections AS T1 JOIN nft_holders AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'Ethereum' GROUP BY T1.contract_address, T1.name", "sql": null }, { "role": "user", "content": "Please filter the results to only include collections that have more than 100 unique holders.", "sql": null }, { "role": "assistant", "content": "SELECT T1.contract_address, T1.name, COUNT(DISTINCT T2.wallet_address) AS unique_holder_count FROM nft_collections AS T1 JOIN nft_holders AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'Ethereum' GROUP BY T1.contract_address, T1.name HAVING COUNT(DISTINCT T2.wallet_address) > 100", "sql": null }, { "role": "user", "content": "Show me the object ID, coin type, and balance for all SUI coins where the status is 'active'.", "sql": null }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance FROM sui_coins WHERE status = 'active'", "sql": null }, { "role": "user", "content": "Also, include the owner address in the result.", "sql": null }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active'", "sql": null }, { "role": "user", "content": "Filter the results to only show coins where the balance is greater than '100000000000'.", "sql": null }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active' AND CAST(balance AS NUMERIC) > 100000000000", "sql": null }, { "role": "user", "content": "Sort the results by balance in descending order and limit the output to 10.", "sql": null }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active' AND CAST(balance AS NUMERIC) > 100000000000 ORDER BY CAST(balance AS NUMERIC) DESC LIMIT 10", "sql": null }, { "role": "user", "content": "List all ERC20 token symbols and their latest prices for tokens where the total supply is greater than '100000000000000000000'.", "sql": null }, { "role": "assistant", "content": "SELECT T1.symbol, T2.price FROM token_metas AS T1 JOIN token_prices_latest AS T2 ON T1.contract_address = T2.address WHERE T1.is_erc20 = 1 AND CAST(T1.total_supply AS NUMERIC) > 100000000000000000000", "sql": null }, { "role": "user", "content": "Can you also include the token name and decimals in the result?", "sql": null }, { "role": "assistant", "content": "SELECT T1.symbol, T1.name, T1.decimals, T2.price FROM token_metas AS T1 JOIN token_prices_latest AS T2 ON T1.contract_address = T2.address WHERE T1.is_erc20 = 1 AND CAST(T1.total_supply AS NUMERIC) > 100000000000000000000", "sql": null }, { "role": "user", "content": "Now, only show tokens where the latest price is above 100.", "sql": null }, { "role": "assistant", "content": "SELECT T1.symbol, T1.name, T1.decimals, T2.price FROM token_metas AS T1 JOIN token_prices_latest AS T2 ON T1.contract_address = T2.address WHERE T1.is_erc20 = 1 AND CAST(T1.total_supply AS NUMERIC) > 100000000000000000000 AND T2.price > 100", "sql": null }, { "role": "user", "content": "Finally, sort the results by price descending and limit to the top 10.", "sql": null }, { "role": "assistant", "content": "SELECT T1.symbol, T1.name, T1.decimals, T2.price FROM token_metas AS T1 JOIN token_prices_latest AS T2 ON T1.contract_address = T2.address WHERE T1.is_erc20 = 1 AND CAST(T1.total_supply AS NUMERIC) > 100000000000000000000 AND T2.price > 100 ORDER BY T2.price DESC LIMIT 10", "sql": null }, { "role": "user", "content": "Show me wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount.", "sql": null }, { "role": "assistant", "content": "SELECT eb.wallet_address, tm.symbol, eb.amount FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address WHERE CAST(eb.amount AS decimal) > 1000;", "sql": null }, { "role": "user", "content": "Can you join this with the token_prices_latest table to include the current price of each token and sort by amount in descending order?", "sql": null }, { "role": "assistant", "content": "SELECT eb.wallet_address, tm.symbol, eb.amount, tpl.price FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE CAST(eb.amount AS decimal) > 1000 ORDER BY CAST(eb.amount AS decimal) DESC;", "sql": null }, { "role": "user", "content": "List all SUI coins with status 'exists', showing their object_id, coin_type, and owner.", "sql": null }, { "role": "assistant", "content": "SELECT object_id, coin_type, owner FROM sui_coins WHERE status = 'exists'", "sql": null }, { "role": "user", "content": "Join with sui_coins_metadata to include the symbol, name, and description for these coins. Filter to only include coins where the description contains the word 'DeFi'.", "sql": null }, { "role": "assistant", "content": "SELECT sc.object_id, sc.coin_type, sc.owner, sm.symbol, sm.name, sm.description FROM sui_coins sc JOIN sui_coins_metadata sm ON sc.coin_type = sm.coin_type WHERE sc.status = 'exists' AND sm.description LIKE '%DeFi%'", "sql": null }, { "role": "user", "content": "Group the results by owner and show the total balance (converted to numeric) for all 'DeFi' coins owned by each address. Order by total balance descending.", "sql": null }, { "role": "assistant", "content": "SELECT sc.owner, SUM(CAST(sc.balance AS REAL)) AS total_balance FROM sui_coins sc JOIN sui_coins_metadata sm ON sc.coin_type = sm.coin_type WHERE sc.status = 'exists' AND sm.description LIKE '%DeFi%' GROUP BY sc.owner ORDER BY total_balance DESC", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )
[ { "role": "user", "content": "Show me how many achievements each player has unlocked.", "sql": null }, { "role": "assistant", "content": "SELECT player_id,\n COUNT(*) AS total_unlocked\nFROM gaming_technology.player_achievements\nGROUP BY player_id;", "sql": null }, { "role": "user", "content": "Now only include players who have unlocked at least 5 achievements.", "sql": null }, { "role": "assistant", "content": "SELECT player_id,\n COUNT(*) AS total_unlocked\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(*) >= 5;", "sql": null }, { "role": "user", "content": "Sort the results by total_unlocked in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT player_id,\n COUNT(*) AS total_unlocked\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(*) >= 5\nORDER BY total_unlocked DESC;", "sql": null }, { "role": "user", "content": "Limit the output to the top 10 players.", "sql": null }, { "role": "assistant", "content": "SELECT player_id,\n COUNT(*) AS total_unlocked\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(*) >= 5\nORDER BY total_unlocked DESC\nLIMIT 10;", "sql": null }, { "role": "user", "content": "Generate a report showing the total number of achievement unlocks broken down by the calendar day they occurred. Show the date and the total number of unlocks for that day.", "sql": null }, { "role": "assistant", "content": "SELECT DATE(unlocked_at) AS unlock_date, COUNT(player_achievement_id) AS unlock_count FROM gaming_technology.player_achievements GROUP BY DATE(unlocked_at);", "sql": null }, { "role": "user", "content": "Only show days with more than 50 unlocks.", "sql": null }, { "role": "assistant", "content": "SELECT DATE(unlocked_at) AS unlock_date, COUNT(player_achievement_id) AS unlock_count FROM gaming_technology.player_achievements GROUP BY DATE(unlocked_at) HAVING COUNT(player_achievement_id) > 50;", "sql": null }, { "role": "user", "content": "Also include the number of unique players who unlocked achievements on those days.", "sql": null }, { "role": "assistant", "content": "SELECT DATE(unlocked_at) AS unlock_date, COUNT(player_achievement_id) AS unlock_count, COUNT(DISTINCT player_id) AS unique_player_count FROM gaming_technology.player_achievements GROUP BY DATE(unlocked_at) HAVING COUNT(player_achievement_id) > 50;", "sql": null }, { "role": "user", "content": "Order the results by unlock_count descending and limit to the top 10 days.", "sql": null }, { "role": "assistant", "content": "SELECT DATE(unlocked_at) AS unlock_date, COUNT(player_achievement_id) AS unlock_count, COUNT(DISTINCT player_id) AS unique_player_count FROM gaming_technology.player_achievements GROUP BY DATE(unlocked_at) HAVING COUNT(player_achievement_id) > 50 ORDER BY unlock_count DESC LIMIT 10;", "sql": null }, { "role": "user", "content": "Can you list for each player their most recent and second most recent achievements, showing columns player_id, recent_achievement_id, second_recent_achievement_id, and recent_unlocked_at?", "sql": null }, { "role": "assistant", "content": "SELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n prev.achievement_id AS second_recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at\nFROM (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn\n FROM gaming_technology.player_achievements\n) recent\nJOIN (\n SELECT player_id, achievement_id,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn\n FROM gaming_technology.player_achievements\n) prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1 AND prev.rn = 2;", "sql": null }, { "role": "user", "content": "Actually, please exclude any players who have less than two unlock records.", "sql": null }, { "role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n prev.achievement_id AS second_recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1\n AND prev.rn = 2\n AND recent.cnt >= 2;", "sql": null }, { "role": "user", "content": "Also include the unlocked_at timestamp of the second most recent achievement.", "sql": null }, { "role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at,\n prev.achievement_id AS second_recent_achievement_id,\n prev.unlocked_at AS second_recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1\n AND prev.rn = 2\n AND recent.cnt >= 2;", "sql": null }, { "role": "user", "content": "Finally, order the output by recent_unlocked_at in descending order.", "sql": null }, { "role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at,\n prev.achievement_id AS second_recent_achievement_id,\n prev.unlocked_at AS second_recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1 AND prev.rn = 2 AND recent.cnt >= 2\nORDER BY recent.unlocked_at DESC;", "sql": null }, { "role": "user", "content": "For each player who has unlocked at least two achievements, find the time difference in minutes between their first and last achievement unlock. Show player_id and the difference labeled last_minus_first_minutes.", "sql": null }, { "role": "assistant", "content": "SELECT player_id, EXTRACT(EPOCH FROM (MAX(unlocked_at) - MIN(unlocked_at))) / 60 AS last_minus_first_minutes FROM gaming_technology.player_achievements GROUP BY player_id HAVING COUNT(player_achievement_id) >= 2;", "sql": null }, { "role": "user", "content": "Only include players where the difference is greater than 60 minutes.", "sql": null }, { "role": "assistant", "content": "SELECT player_id, EXTRACT(EPOCH FROM (MAX(unlocked_at) - MIN(unlocked_at))) / 60 AS last_minus_first_minutes FROM gaming_technology.player_achievements GROUP BY player_id HAVING COUNT(player_achievement_id) >= 2 AND EXTRACT(EPOCH FROM (MAX(unlocked_at) - MIN(unlocked_at))) / 60 > 60;", "sql": null }, { "role": "user", "content": "Now, instead of the total difference, I want to find players who unlocked at least two *different* achievements within the *same hour* on the same day. Show their player_id and the date.", "sql": null }, { "role": "assistant", "content": "SELECT DISTINCT p1.player_id, DATE(p1.unlocked_at) AS unlock_date FROM gaming_technology.player_achievements p1 JOIN gaming_technology.player_achievements p2 ON p1.player_id = p2.player_id AND p1.achievement_id <> p2.achievement_id WHERE DATE(p1.unlocked_at) = DATE(p2.unlocked_at) AND EXTRACT(HOUR FROM p1.unlocked_at) = EXTRACT(HOUR FROM p2.unlocked_at);", "sql": null }, { "role": "user", "content": "Filter this list to only show players who achieved this on a date after '2024-01-01' and order by the date descending.", "sql": null }, { "role": "assistant", "content": "SELECT DISTINCT p1.player_id, DATE(p1.unlocked_at) AS unlock_date FROM gaming_technology.player_achievements p1 JOIN gaming_technology.player_achievements p2 ON p1.player_id = p2.player_id AND p1.achievement_id <> p2.achievement_id WHERE DATE(p1.unlocked_at) = DATE(p2.unlocked_at) AND EXTRACT(HOUR FROM p1.unlocked_at) = EXTRACT(HOUR FROM p2.unlocked_at) AND DATE(p1.unlocked_at) > '2024-01-01' ORDER BY unlock_date DESC;", "sql": null }, { "role": "user", "content": "List all pairs of players who unlocked the same achievement, showing achievement_id, player1_id, player2_id, and player1_unlocked_at.", "sql": null }, { "role": "assistant", "content": "SELECT pa1.achievement_id,\n pa1.player_id AS player1_id,\n pa2.player_id AS player2_id,\n pa1.unlocked_at AS player1_unlocked_at\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.achievement_id = pa2.achievement_id;", "sql": null }, { "role": "user", "content": "Ensure each pair appears only once by requiring player1_id < player2_id.", "sql": null }, { "role": "assistant", "content": "SELECT pa1.achievement_id,\n pa1.player_id AS player1_id,\n pa2.player_id AS player2_id,\n pa1.unlocked_at AS player1_unlocked_at\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.achievement_id = pa2.achievement_id\nWHERE pa1.player_id < pa2.player_id;", "sql": null }, { "role": "user", "content": "And only include pairs where the two unlocks occurred within one hour of each other.", "sql": null }, { "role": "assistant", "content": "SELECT pa1.achievement_id,\n pa1.player_id AS player1_id,\n pa2.player_id AS player2_id,\n pa1.unlocked_at AS player1_unlocked_at,\n pa2.unlocked_at AS player2_unlocked_at\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.achievement_id = pa2.achievement_id\nWHERE pa1.player_id < pa2.player_id\n AND ABS(EXTRACT(EPOCH FROM (pa1.unlocked_at - pa2.unlocked_at))) <= 3600;", "sql": null }, { "role": "user", "content": "Which achievement_id was unlocked the most times in the first quarter of 2024?", "sql": null }, { "role": "assistant", "content": "SELECT achievement_id, COUNT(*) as unlock_count FROM gaming_technology.player_achievements WHERE unlocked_at >= '2024-01-01 00:00:00+00' AND unlocked_at < '2024-04-01 00:00:00+00' GROUP BY achievement_id ORDER BY unlock_count DESC LIMIT 1;", "sql": null }, { "role": "user", "content": "Okay, now show me the player_id who unlocked any achievement the most times during the same period (first quarter of 2024).", "sql": null }, { "role": "assistant", "content": "SELECT player_id, COUNT(*) as unlock_count FROM gaming_technology.player_achievements WHERE unlocked_at >= '2024-01-01 00:00:00+00' AND unlocked_at < '2024-04-01 00:00:00+00' GROUP BY player_id ORDER BY unlock_count DESC LIMIT 1;", "sql": null }, { "role": "user", "content": "Can you list all achievements unlocked by player 'a1b2c3d4-e5f6-7890-1234-000000000001' on the date '2024-01-15'?", "sql": null }, { "role": "assistant", "content": "SELECT achievement_id, unlocked_at FROM gaming_technology.player_achievements WHERE player_id = 'a1b2c3d4-e5f6-7890-1234-000000000001' AND unlocked_at >= '2024-01-15 00:00:00+00' AND unlocked_at < '2024-01-16 00:00:00+00' ORDER BY unlocked_at;", "sql": null }, { "role": "user", "content": "And how many distinct achievements did player 'a1b2c3d4-e5f6-7890-1234-000000000001' unlock in total *before* 2024?", "sql": null }, { "role": "assistant", "content": "SELECT COUNT(DISTINCT achievement_id) FROM gaming_technology.player_achievements WHERE player_id = 'a1b2c3d4-e5f6-7890-1234-000000000001' AND unlocked_at < '2024-01-01 00:00:00+00';", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric ) 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 token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric ) CREATE TABLE cex_token_balance ( snapshot_time.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 )
[ { "role": "user", "content": "For each chain in the smart money token inflow data, calculate the total number of addresses involved in buy transactions and the total number of addresses involved in sell transactions. Display the chain, total buy addresses, and total sell addresses.", "sql": null }, { "role": "assistant", "content": "SELECT chain, SUM(CASE WHEN type = 1 THEN address_amount ELSE 0 END) AS total_buy_addresses, SUM(CASE WHEN type = 2 THEN address_amount ELSE 0 END) AS total_sell_addresses FROM smart_money_token_inflow WHERE type IN (1, 2) GROUP BY chain;", "sql": null }, { "role": "user", "content": "What is the total USD value of tokens held by CEXes for tokens belonging to the 'DeFi' narrative on the 'Ethereum' chain? Show the narrative, chain, and total value.", "sql": null }, { "role": "assistant", "content": "SELECT T2.narrative, T1.chain, SUM(T1.usd_value) AS total_usd_value FROM cex_token_balance AS T1 JOIN token_basic_info AS T2 ON T1.token_symbol = T2.token_symbol WHERE T2.narrative = 'DeFi' AND T1.chain = 'Ethereum' GROUP BY T2.narrative, T1.chain;", "sql": null }, { "role": "user", "content": "Instead of just 'DeFi' on 'Ethereum', show the top 5 narratives with the highest total USD value across *all* chains in CEX balances. Also include the count of distinct token symbols for each narrative.", "sql": null }, { "role": "assistant", "content": "SELECT T2.narrative, SUM(T1.usd_value) AS total_usd_value, COUNT(DISTINCT T1.token_symbol) AS token_count FROM cex_token_balance AS T1 JOIN token_basic_info AS T2 ON T1.token_symbol = T2.token_symbol WHERE T2.narrative IS NOT NULL GROUP BY T2.narrative ORDER BY total_usd_value DESC LIMIT 5;", "sql": null }, { "role": "user", "content": "Show all tokens on the Ethereum chain in token_dexpool_info that had a price increase in the last 6 hours, along with their 24h trading volume and smart money ROI.", "sql": null }, { "role": "assistant", "content": "SELECT td.token_symbol,\n td.price_change_percentage_6h,\n td.volume_24h,\n smtp.roi\nFROM token_dexpool_info AS td\nJOIN smart_money_token_performance AS smtp\n ON td.token_symbol = smtp.token_symbol\n AND td.chain = smtp.chain\nWHERE td.chain = 'Ethereum'\n AND td.price_change_percentage_6h > 0;", "sql": null }, { "role": "user", "content": "I only want tokens with liquidity over 1,000,000 and ROI above 1. Show the price_change_24h as well.", "sql": null }, { "role": "assistant", "content": "SELECT td.token_symbol,\n td.price_change_percentage_6h,\n td.price_change_percentage_24h,\n td.volume_24h,\n td.liquidity,\n smtp.roi\nFROM token_dexpool_info AS td\nJOIN smart_money_token_performance AS smtp\n ON td.token_symbol = smtp.token_symbol\n AND td.chain = smtp.chain\nWHERE td.chain = 'Ethereum'\n AND td.price_change_percentage_6h > 0\n AND td.liquidity > 1000000\n AND smtp.roi > 1;", "sql": null }, { "role": "user", "content": "Which chain has the highest average ROI among all tokens in smart_money_token_performance? Show the chain and the average ROI.", "sql": null }, { "role": "assistant", "content": "SELECT chain, AVG(roi) AS avg_roi\nFROM smart_money_token_performance\nGROUP BY chain\nORDER BY avg_roi DESC\nLIMIT 1;", "sql": null }, { "role": "user", "content": "Could you also include the total number of tokens analyzed for that chain?", "sql": null }, { "role": "assistant", "content": "SELECT chain, AVG(roi) AS avg_roi, COUNT(DISTINCT token_symbol) AS token_count\nFROM smart_money_token_performance\nGROUP BY chain\nORDER BY avg_roi DESC\nLIMIT 1;", "sql": null }, { "role": "user", "content": "List all projects that raised funds in March 2023. For each project, show its name, amount raised, fundraising round, and the token symbol and price of its associated token.", "sql": null }, { "role": "assistant", "content": "SELECT p.project_name, p.investment_value, p.rounds_name, t.token_symbol, t.price\nFROM project_fundraising_record p\nLEFT JOIN token_basic_info t ON LOWER(p.project_name) = LOWER(t.token_name)\nWHERE p.investment_date LIKE '2023-03%'", "sql": null }, { "role": "user", "content": "Can you also include the current market cap and chain of each token in the result?", "sql": null }, { "role": "assistant", "content": "SELECT p.project_name, p.investment_value, p.rounds_name, t.token_symbol, t.price, t.market_cap, t.chain\nFROM project_fundraising_record p\nLEFT JOIN token_basic_info t ON LOWER(p.project_name) = LOWER(t.token_name)\nWHERE p.investment_date LIKE '2023-03%'", "sql": null }, { "role": "user", "content": "I only want to see projects that raised more than $5,000,000. Please update the query.", "sql": null }, { "role": "assistant", "content": "SELECT p.project_name, p.investment_value, p.rounds_name, t.token_symbol, t.price, t.market_cap, t.chain\nFROM project_fundraising_record p\nLEFT JOIN token_basic_info t ON LOWER(p.project_name) = LOWER(t.token_name)\nWHERE p.investment_date LIKE '2023-03%' AND p.investment_value > 5000000", "sql": null }, { "role": "user", "content": "It seems some tokens are not matched because names are not identical. Can you try joining where the token_name contains the project_name (case-insensitive)?", "sql": null }, { "role": "assistant", "content": "SELECT p.project_name, p.investment_value, p.rounds_name, t.token_symbol, t.price, t.market_cap, t.chain\nFROM project_fundraising_record p\nLEFT JOIN token_basic_info t ON LOWER(t.token_name) LIKE '%' || LOWER(p.project_name) || '%'\nWHERE p.investment_date LIKE '2023-03%' AND p.investment_value > 5000000", "sql": null }, { "role": "user", "content": "Show me the top 3 tokens with the highest 7-day price change percentage. Display their symbol, chain, and 7d price change.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, price_change_percentage_7d\nFROM token_basic_info\nORDER BY price_change_percentage_7d DESC\nLIMIT 3", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )
[ { "role": "user", "content": "Show me the appointment ID, start time, and subject for all appointments scheduled with lawyer 'lawyer123'.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, start_time, subject FROM legal_services.appointments WHERE lawyer_id = 'lawyer123';", "sql": null }, { "role": "user", "content": "Only include those appointments where the status is 'Scheduled'.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, start_time, subject FROM legal_services.appointments WHERE lawyer_id = 'lawyer123' AND status = 'Scheduled';", "sql": null }, { "role": "user", "content": "Further filter to only show appointments starting after '2024-07-01'.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, start_time, subject FROM legal_services.appointments WHERE lawyer_id = 'lawyer123' AND status = 'Scheduled' AND start_time > '2024-07-01';", "sql": null }, { "role": "user", "content": "Show me the subject and start times of all appointments along with the corresponding lawyer IDs for each client.", "sql": null }, { "role": "assistant", "content": "SELECT client_id, lawyer_id, subject, start_time FROM legal_services.appointments;", "sql": null }, { "role": "user", "content": "List all appointments that took place at 'Central Office', showing appointment_id, client_id, and subject.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, client_id, subject FROM legal_services.appointments WHERE location = 'Central Office';", "sql": null }, { "role": "user", "content": "Actually, can you also include the lawyer_id in the results?", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, client_id, lawyer_id, subject FROM legal_services.appointments WHERE location = 'Central Office';", "sql": null }, { "role": "user", "content": "Also, only show those appointments with status 'Completed'.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, client_id, lawyer_id, subject FROM legal_services.appointments WHERE location = 'Central Office' AND status = 'Completed';", "sql": null }, { "role": "user", "content": "List all appointments that have a location specified and their status is not 'Cancelled'. Show the appointment ID, subject, and location.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, subject, location FROM legal_services.appointments WHERE location IS NOT NULL AND status <> 'Cancelled';", "sql": null }, { "role": "user", "content": "Also, include appointments that have a case ID assigned. Order the final list by start time ascending.", "sql": null }, { "role": "assistant", "content": "SELECT appointment_id, subject, location FROM legal_services.appointments WHERE (location IS NOT NULL AND status <> 'Cancelled') OR case_id IS NOT NULL ORDER BY start_time ASC;", "sql": null }, { "role": "user", "content": "What is the count of appointments for each lawyer? Display the lawyer ID and the total count.", "sql": null }, { "role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments GROUP BY lawyer_id;", "sql": null }, { "role": "user", "content": "Only show lawyers who have more than 5 appointments.", "sql": null }, { "role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments GROUP BY lawyer_id HAVING COUNT(*) > 5;", "sql": null }, { "role": "user", "content": "Consider only appointments that were created in the year 2023.", "sql": null }, { "role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments WHERE created_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59' GROUP BY lawyer_id HAVING COUNT(*) > 5;", "sql": null }, { "role": "user", "content": "Order the results by the appointment count in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments WHERE created_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59' GROUP BY lawyer_id HAVING COUNT(*) > 5 ORDER BY appointment_count DESC;", "sql": null }, { "role": "user", "content": "How many appointments have a status of 'Cancelled'?", "sql": null }, { "role": "assistant", "content": "SELECT COUNT(*) FROM legal_services.appointments WHERE status = 'Cancelled';", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE legal_services.time_entries ( entry_id character varying(64) NOT NULL, -- unique identifier for the time entry case_id character varying(64) NOT NULL, -- FK to cases table lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work) date_worked date NOT NULL, -- date the work was performed hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m) billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry description text NOT NULL, -- detailed description of the work performed is_billable boolean DEFAULT true, -- whether this time entry is billable to the client is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice invoice_id character varying(64), -- FK to invoices table (once billed) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded PRIMARY KEY (entry_id) )
[ { "role": "user", "content": "I want to see all time entries where the description contains the word 'draft' and that have not been billed yet.", "sql": null }, { "role": "assistant", "content": "SELECT *\nFROM legal_services.time_entries\nWHERE description ILIKE '%draft%'\n AND is_billed = false;", "sql": null }, { "role": "user", "content": "Only include entries that were logged in June 2024.", "sql": null }, { "role": "assistant", "content": "SELECT *\nFROM legal_services.time_entries\nWHERE description ILIKE '%draft%'\n AND is_billed = false\n AND date_worked BETWEEN '2024-06-01' AND '2024-06-30';", "sql": null }, { "role": "user", "content": "Now only show entries that are billable and where hours_spent is greater than 2.", "sql": null }, { "role": "assistant", "content": "SELECT *\nFROM legal_services.time_entries\nWHERE description ILIKE '%draft%'\n AND is_billed = false\n AND is_billable = true\n AND date_worked BETWEEN '2024-06-01' AND '2024-06-30'\n AND hours_spent > 2;", "sql": null }, { "role": "user", "content": "Please only include the entry_id, lawyer_id, date_worked, and hours_spent in the output.", "sql": null }, { "role": "assistant", "content": "SELECT entry_id, lawyer_id, date_worked, hours_spent\nFROM legal_services.time_entries\nWHERE description ILIKE '%draft%'\n AND is_billed = false\n AND is_billable = true\n AND date_worked BETWEEN '2024-06-01' AND '2024-06-30'\n AND hours_spent > 2;", "sql": null }, { "role": "user", "content": "Get me all unbilled billable time entries with their entry_id, case_id, lawyer_id, hours_spent, and billing_rate.", "sql": null }, { "role": "assistant", "content": "SELECT entry_id,\n case_id,\n lawyer_id,\n hours_spent,\n billing_rate\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND is_billed = FALSE;", "sql": null }, { "role": "user", "content": "Actually, I only want entries for lawyer 'lawyer_123'.", "sql": null }, { "role": "assistant", "content": "SELECT entry_id,\n case_id,\n lawyer_id,\n hours_spent,\n billing_rate\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND is_billed = FALSE\n AND lawyer_id = 'lawyer_123';", "sql": null }, { "role": "user", "content": "Also, sort the results by hours_spent in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT entry_id,\n case_id,\n lawyer_id,\n hours_spent,\n billing_rate\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND is_billed = FALSE\n AND lawyer_id = 'lawyer_123'\nORDER BY hours_spent DESC;", "sql": null }, { "role": "user", "content": "Show me all pairs of time entries made by the same lawyer on the same date. Include both entry IDs, lawyer_id, and date_worked.", "sql": null }, { "role": "assistant", "content": "SELECT t1.lawyer_id, t1.date_worked, t1.entry_id AS entry_id_1, t2.entry_id AS entry_id_2\nFROM legal_services.time_entries t1\nJOIN legal_services.time_entries t2\n ON t1.lawyer_id = t2.lawyer_id\n AND t1.date_worked = t2.date_worked\nWHERE t1.entry_id < t2.entry_id;", "sql": null }, { "role": "user", "content": "Actually, only include pairs where both entries are billable.", "sql": null }, { "role": "assistant", "content": "SELECT t1.lawyer_id, t1.date_worked, t1.entry_id AS entry_id_1, t2.entry_id AS entry_id_2\nFROM legal_services.time_entries t1\nJOIN legal_services.time_entries t2\n ON t1.lawyer_id = t2.lawyer_id\n AND t1.date_worked = t2.date_worked\nWHERE t1.entry_id < t2.entry_id\n AND t1.is_billable = true\n AND t2.is_billable = true;", "sql": null }, { "role": "user", "content": "Also, ensure that the two entries have different hours_spent values.", "sql": null }, { "role": "assistant", "content": "SELECT t1.lawyer_id, t1.date_worked, t1.entry_id AS entry_id_1, t2.entry_id AS entry_id_2\nFROM legal_services.time_entries t1\nJOIN legal_services.time_entries t2\n ON t1.lawyer_id = t2.lawyer_id\n AND t1.date_worked = t2.date_worked\nWHERE t1.entry_id < t2.entry_id\n AND t1.is_billable = true\n AND t2.is_billable = true\n AND t1.hours_spent <> t2.hours_spent;", "sql": null }, { "role": "user", "content": "Show me all time entries from the last 90 days, including the entry description, hours spent, the name of the case, and the name of the client.", "sql": null }, { "role": "assistant", "content": "SELECT T1.description, T1.hours_spent, T2.case_name, T3.first_name, T3.last_name FROM legal_services.time_entries AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id JOIN clients AS T3 ON T2.client_id = T3.client_id WHERE T1.date_worked >= CURRENT_DATE - INTERVAL '90 days';", "sql": null }, { "role": "user", "content": "Calculate the total billable hours spent by each lawyer for entries in March 2024.", "sql": null }, { "role": "assistant", "content": "SELECT lawyer_id,\n SUM(hours_spent) AS total_hours\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND date_worked BETWEEN '2024-03-01' AND '2024-03-31'\nGROUP BY lawyer_id;", "sql": null }, { "role": "user", "content": "Show me the total hours spent by each lawyer on billable time entries in 2024.", "sql": null }, { "role": "assistant", "content": "SELECT\n lawyer_id,\n SUM(hours_spent) AS total_hours\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND EXTRACT(YEAR FROM date_worked) = 2024\nGROUP BY lawyer_id;", "sql": null }, { "role": "user", "content": "Actually, only include entries that have not yet been billed.", "sql": null }, { "role": "assistant", "content": "SELECT\n lawyer_id,\n SUM(hours_spent) AS total_hours\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND is_billed = FALSE\n AND EXTRACT(YEAR FROM date_worked) = 2024\nGROUP BY lawyer_id;", "sql": null }, { "role": "user", "content": "And restrict this to entries recorded after June 30, 2024.", "sql": null }, { "role": "assistant", "content": "SELECT\n lawyer_id,\n SUM(hours_spent) AS total_hours\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND is_billed = FALSE\n AND date_worked > '2024-06-30'\n AND EXTRACT(YEAR FROM date_worked) = 2024\nGROUP BY lawyer_id;", "sql": null }, { "role": "user", "content": "Finally, order the results by total_hours descending.", "sql": null }, { "role": "assistant", "content": "SELECT\n lawyer_id,\n SUM(hours_spent) AS total_hours\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND is_billed = FALSE\n AND date_worked > '2024-06-30'\n AND EXTRACT(YEAR FROM date_worked) = 2024\nGROUP BY lawyer_id\nORDER BY total_hours DESC;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )
[ { "role": "user", "content": "Find pairs of citizens who have the same last name but different national_id_number.", "sql": null }, { "role": "assistant", "content": "SELECT c1.citizen_id AS citizen_id_1, c1.first_name AS first_name_1, c1.last_name AS last_name_1, c1.national_id_number AS national_id_1, c2.citizen_id AS citizen_id_2, c2.first_name AS first_name_2, c2.last_name AS last_name_2, c2.national_id_number AS national_id_2\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.last_name = c2.last_name\n AND c1.national_id_number <> c2.national_id_number\n AND c1.citizen_id < c2.citizen_id;", "sql": null }, { "role": "user", "content": "Actually, only include pairs where both citizens are verified.", "sql": null }, { "role": "assistant", "content": "SELECT c1.citizen_id AS citizen_id_1, c1.first_name AS first_name_1, c1.last_name AS last_name_1, c1.national_id_number AS national_id_1, c2.citizen_id AS citizen_id_2, c2.first_name AS first_name_2, c2.last_name AS last_name_2, c2.national_id_number AS national_id_2\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.last_name = c2.last_name\n AND c1.national_id_number <> c2.national_id_number\n AND c1.is_verified = TRUE\n AND c2.is_verified = TRUE\n AND c1.citizen_id < c2.citizen_id;", "sql": null }, { "role": "user", "content": "How many citizens are there in each gender?", "sql": null }, { "role": "assistant", "content": "SELECT gender, COUNT(*) AS citizen_count\nFROM government_services.citizens\nGROUP BY gender;", "sql": null }, { "role": "user", "content": "Filter to only include genders with more than 200 citizens.", "sql": null }, { "role": "assistant", "content": "SELECT gender, COUNT(*) AS citizen_count\nFROM government_services.citizens\nGROUP BY gender\nHAVING COUNT(*) > 200;", "sql": null }, { "role": "user", "content": "Also show the most recent registration date for each gender.", "sql": null }, { "role": "assistant", "content": "SELECT gender, COUNT(*) AS citizen_count, MAX(registration_date) AS latest_registration\nFROM government_services.citizens\nGROUP BY gender\nHAVING COUNT(*) > 200;", "sql": null }, { "role": "user", "content": "Order the results by citizen_count in descending order and limit to top 2.", "sql": null }, { "role": "assistant", "content": "SELECT gender, COUNT(*) AS citizen_count, MAX(registration_date) AS latest_registration\nFROM government_services.citizens\nGROUP BY gender\nHAVING COUNT(*) > 200\nORDER BY citizen_count DESC\nLIMIT 2;", "sql": null }, { "role": "user", "content": "Retrieve each gender and the count of verified citizens born before 1990.", "sql": null }, { "role": "assistant", "content": "SELECT gender,\n COUNT(*) AS citizen_count\nFROM government_services.citizens\nWHERE is_verified = TRUE\n AND date_of_birth < '1990-01-01'\nGROUP BY gender;", "sql": null }, { "role": "user", "content": "Now only include genders with more than 100 such citizens.", "sql": null }, { "role": "assistant", "content": "SELECT gender,\n COUNT(*) AS citizen_count\nFROM government_services.citizens\nWHERE is_verified = TRUE\n AND date_of_birth < '1990-01-01'\nGROUP BY gender\nHAVING COUNT(*) > 100;", "sql": null }, { "role": "user", "content": "Also show the average age of these citizens as of today.", "sql": null }, { "role": "assistant", "content": "SELECT gender,\n COUNT(*) AS citizen_count,\n AVG(EXTRACT(YEAR FROM age(CURRENT_DATE, date_of_birth))) AS avg_age\nFROM government_services.citizens\nWHERE is_verified = TRUE\n AND date_of_birth < '1990-01-01'\nGROUP BY gender\nHAVING COUNT(*) > 100;", "sql": null }, { "role": "user", "content": "Order results by the citizen count descending.", "sql": null }, { "role": "assistant", "content": "SELECT gender,\n COUNT(*) AS citizen_count,\n AVG(EXTRACT(YEAR FROM age(CURRENT_DATE, date_of_birth))) AS avg_age\nFROM government_services.citizens\nWHERE is_verified = TRUE\n AND date_of_birth < '1990-01-01'\nGROUP BY gender\nHAVING COUNT(*) > 100\nORDER BY citizen_count DESC;", "sql": null }, { "role": "user", "content": "List all pairs of citizens who registered on the same date. Include each citizen's full name and the shared registration date.", "sql": null }, { "role": "assistant", "content": "SELECT c1.first_name || ' ' || c1.last_name AS full_name_1,\n c2.first_name || ' ' || c2.last_name AS full_name_2,\n DATE(c1.registration_date) AS registration_date\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON DATE(c1.registration_date) = DATE(c2.registration_date)\n AND c1.citizen_id < c2.citizen_id;", "sql": null }, { "role": "user", "content": "Find pairs of citizens who share the same gender but registered in different years. Show each citizen's first and last name along with their registration year.", "sql": null }, { "role": "assistant", "content": "SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n EXTRACT(YEAR FROM c1.registration_date) AS reg_year_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c2.registration_date) AS reg_year_2\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.gender = c2.gender\n AND EXTRACT(YEAR FROM c1.registration_date) <> EXTRACT(YEAR FROM c2.registration_date)\n AND c1.citizen_id < c2.citizen_id;", "sql": null }, { "role": "user", "content": "Exclude any pairs where either citizen is not verified.", "sql": null }, { "role": "assistant", "content": "SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n EXTRACT(YEAR FROM c1.registration_date) AS reg_year_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c2.registration_date) AS reg_year_2\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.gender = c2.gender\n AND EXTRACT(YEAR FROM c1.registration_date) <> EXTRACT(YEAR FROM c2.registration_date)\n AND c1.citizen_id < c2.citizen_id\nWHERE c1.is_verified = TRUE\n AND c2.is_verified = TRUE;", "sql": null }, { "role": "user", "content": "Find all male-female citizen pairs born in the same year. Display the male's full name, the female's full name, and their shared birth year.", "sql": null }, { "role": "assistant", "content": "SELECT\n m.first_name || ' ' || m.last_name AS male_full_name,\n f.first_name || ' ' || f.last_name AS female_full_name,\n EXTRACT(YEAR FROM m.date_of_birth) AS birth_year\nFROM government_services.citizens m\nJOIN government_services.citizens f\n ON EXTRACT(YEAR FROM m.date_of_birth) = EXTRACT(YEAR FROM f.date_of_birth)\n AND m.gender = 'Male'\n AND f.gender = 'Female';", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )
[ { "role": "user", "content": "List the claim ID, incident date, estimated loss, and the first and last name of the customer for all claims with an estimated loss greater than 5000.", "sql": null }, { "role": "assistant", "content": "SELECT T1.claim_id, T1.incident_date, T1.estimated_loss, T2.first_name, T2.last_name FROM insurance.claims AS T1 JOIN insurance.customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.estimated_loss > 5000;", "sql": null }, { "role": "user", "content": "Also, only include claims where the incident date is in the year 2024.", "sql": null }, { "role": "assistant", "content": "SELECT T1.claim_id, T1.incident_date, T1.estimated_loss, T2.first_name, T2.last_name FROM insurance.claims AS T1 JOIN insurance.customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.estimated_loss > 5000 AND STRFTIME('%Y', T1.incident_date) = '2024';", "sql": null }, { "role": "user", "content": "Show me all claims handled by agent 'AG123' along with their settlement details.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, settlement_amount, settlement_date FROM insurance.claims WHERE claim_handler_id = 'AG123';", "sql": null }, { "role": "user", "content": "I want to see only claims that were settled for more than $10,000.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, settlement_amount, settlement_date FROM insurance.claims WHERE claim_handler_id = 'AG123' AND settlement_amount > 10000;", "sql": null }, { "role": "user", "content": "Now include the time it took to settle these claims (difference between reported_date and settlement_date).", "sql": null }, { "role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, settlement_amount, settlement_date, DATEDIFF(settlement_date, reported_date) AS days_to_settle FROM insurance.claims WHERE claim_handler_id = 'AG123' AND settlement_amount > 10000;", "sql": null }, { "role": "user", "content": "Finally, order the results by the longest settlement time first.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, settlement_amount, settlement_date, DATEDIFF(settlement_date, reported_date) AS days_to_settle FROM insurance.claims WHERE claim_handler_id = 'AG123' AND settlement_amount > 10000 ORDER BY days_to_settle DESC;", "sql": null }, { "role": "user", "content": "List each claim_handler_id and the number of claims they handled that were reported in 2023.", "sql": null }, { "role": "assistant", "content": "SELECT claim_handler_id,\n COUNT(*) AS claims_count\nFROM insurance.claims\nWHERE reported_date::date BETWEEN '2023-01-01' AND '2023-12-31'\nGROUP BY claim_handler_id;", "sql": null }, { "role": "user", "content": "Retrieve customer_id for customers who have a denied claim and an approved claim on the same incident_date. Show customer_id, denied_claim_id, approved_claim_id, and incident_date.", "sql": null }, { "role": "assistant", "content": "SELECT c_denied.customer_id,\n c_denied.claim_id AS denied_claim_id,\n c_approved.claim_id AS approved_claim_id,\n c_denied.incident_date::date AS incident_date\nFROM insurance.claims c_denied\nJOIN insurance.claims c_approved\n ON c_denied.customer_id = c_approved.customer_id\n AND c_denied.incident_date::date = c_approved.incident_date::date\nWHERE c_denied.status = 'denied'\n AND c_approved.status = 'approved';", "sql": null }, { "role": "user", "content": "Actually, restrict to only include cases where the approved claim's estimated_loss is greater than the denied claim's estimated_loss.", "sql": null }, { "role": "assistant", "content": "SELECT c_denied.customer_id,\n c_denied.claim_id AS denied_claim_id,\n c_approved.claim_id AS approved_claim_id,\n c_denied.incident_date::date AS incident_date\nFROM insurance.claims c_denied\nJOIN insurance.claims c_approved\n ON c_denied.customer_id = c_approved.customer_id\n AND c_denied.incident_date::date = c_approved.incident_date::date\nWHERE c_denied.status = 'denied'\n AND c_approved.status = 'approved'\n AND c_approved.estimated_loss > c_denied.estimated_loss;", "sql": null }, { "role": "user", "content": "Find any two claims made by the same customer on the same day. Return customer_id, the two claim IDs, and the incident date.", "sql": null }, { "role": "assistant", "content": "SELECT c1.customer_id,\n c1.claim_id AS claim1_id,\n c2.claim_id AS claim2_id,\n DATE(c1.incident_date) AS incident_date\nFROM insurance.claims c1\nJOIN insurance.claims c2\n ON c1.customer_id = c2.customer_id\n AND DATE(c1.incident_date) = DATE(c2.incident_date)\n AND c1.claim_id < c2.claim_id;", "sql": null }, { "role": "user", "content": "What is the total estimated_loss and average settlement_amount for all claims with status 'Approved'?", "sql": null }, { "role": "assistant", "content": "SELECT SUM(estimated_loss) AS total_estimated_loss,\n AVG(settlement_amount) AS average_settlement\nFROM insurance.claims\nWHERE status = 'Approved';", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp name character varying(128) NOT NULL, -- name of the DApp description text NOT NULL, -- description of the DApp url character varying(256) NOT NULL, -- URL of the DApp PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit user_id character varying(64) NOT NULL, -- identifier of the user being audited status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected) reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed PRIMARY KEY (kyc_audit_id) )
[ { "role": "user", "content": "Show me the names and URLs of all DApps, and for each DApp, list the KYC status and last review date for all users who have an audit entry.", "sql": null }, { "role": "assistant", "content": "SELECT d.name AS dapp_name, d.url, k.user_id, k.status, k.reviewed_at\nFROM trading_platform.dapps d\nJOIN trading_platform.kyc_audit k ON 1=1\nORDER BY d.name, k.user_id;", "sql": null }, { "role": "user", "content": "I only want DApps whose name includes the word 'market', and for KYC audits, show only those with status 'approved'.", "sql": null }, { "role": "assistant", "content": "SELECT d.name AS dapp_name, d.url, k.user_id, k.status, k.reviewed_at\nFROM trading_platform.dapps d\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE d.name ILIKE '%market%' AND k.status = 'approved'\nORDER BY d.name, k.user_id;", "sql": null }, { "role": "user", "content": "List the names of all DApps whose description contains the word 'auction' along with the user IDs of anyone who has had a KYC audit.", "sql": null }, { "role": "assistant", "content": "SELECT d.name AS dapp_name, k.user_id\nFROM trading_platform.dapps d\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE d.description ILIKE '%auction%'\nORDER BY d.name, k.user_id;", "sql": null }, { "role": "user", "content": "Just show KYC audits with a status that is not 'approved'.", "sql": null }, { "role": "assistant", "content": "SELECT d.name AS dapp_name, k.user_id, k.status\nFROM trading_platform.dapps d\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE d.description ILIKE '%auction%'\n AND k.status <> 'approved'\nORDER BY d.name, k.user_id;", "sql": null }, { "role": "user", "content": "Actually, I want to include the reviewed_at time for each audit result too.", "sql": null }, { "role": "assistant", "content": "SELECT d.name AS dapp_name, k.user_id, k.status, k.reviewed_at\nFROM trading_platform.dapps d\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE d.description ILIKE '%auction%'\n AND k.status <> 'approved'\nORDER BY d.name, k.user_id, k.reviewed_at;", "sql": null }, { "role": "user", "content": "Filter further to only show audits reviewed after January 1, 2024.", "sql": null }, { "role": "assistant", "content": "SELECT d.name AS dapp_name, k.user_id, k.status, k.reviewed_at\nFROM trading_platform.dapps d\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE d.description ILIKE '%auction%'\n AND k.status <> 'approved'\n AND k.reviewed_at > '2024-01-01'\nORDER BY d.name, k.user_id, k.reviewed_at;", "sql": null }, { "role": "user", "content": "How many unique users have a KYC audit record with status 'pending'?", "sql": null }, { "role": "assistant", "content": "SELECT COUNT(DISTINCT user_id) AS pending_kyc_users\nFROM trading_platform.kyc_audit\nWHERE status = 'pending';", "sql": null }, { "role": "user", "content": "Show me all KYC audit records for user ID 'user_abc_123'.", "sql": null }, { "role": "assistant", "content": "SELECT kyc_audit_id, user_id, status, reviewed_at FROM kyc_audit WHERE user_id = 'user_abc_123';", "sql": null }, { "role": "user", "content": "From those, list only the ones with status 'pending'.", "sql": null }, { "role": "assistant", "content": "SELECT kyc_audit_id, user_id, status, reviewed_at FROM kyc_audit WHERE user_id = 'user_abc_123' AND status = 'pending';", "sql": null }, { "role": "user", "content": "Order the results by the review date in ascending order.", "sql": null }, { "role": "assistant", "content": "SELECT kyc_audit_id, user_id, status, reviewed_at FROM kyc_audit WHERE user_id = 'user_abc_123' AND status = 'pending' ORDER BY reviewed_at ASC;", "sql": null }, { "role": "user", "content": "Just show the latest pending audit for that user, displaying the user_id, status, and reviewed_at date.", "sql": null }, { "role": "assistant", "content": "SELECT user_id, status, reviewed_at FROM kyc_audit WHERE user_id = 'user_abc_123' AND status = 'pending' ORDER BY reviewed_at DESC LIMIT 1;", "sql": null }, { "role": "user", "content": "Show me the top 5 users with the most KYC audits, along with their latest audit status.", "sql": null }, { "role": "assistant", "content": "SELECT user_id, status, COUNT(*) as audit_count FROM trading_platform.kyc_audit GROUP BY user_id, status ORDER BY audit_count DESC LIMIT 5;", "sql": null }, { "role": "user", "content": "Now modify the query to show only users whose latest KYC status was rejected.", "sql": null }, { "role": "assistant", "content": "WITH latest_audit AS (SELECT user_id, status, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY reviewed_at DESC) as rn FROM trading_platform.kyc_audit) SELECT user_id, status FROM latest_audit WHERE rn = 1 AND status = 'rejected' LIMIT 5;", "sql": null }, { "role": "user", "content": "Actually, I want to see the count of rejected audits per user instead of just the latest status.", "sql": null }, { "role": "assistant", "content": "SELECT user_id, COUNT(*) as rejected_count FROM trading_platform.kyc_audit WHERE status = 'rejected' GROUP BY user_id ORDER BY rejected_count DESC LIMIT 5;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp ) CREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp ) CREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text ) CREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp ) CREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp ) CREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp ) CREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text ) CREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text ) CREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )
[ { "role": "user", "content": "Show me all service orders for spa services in the last month, including the guest name and staff who delivered the service.", "sql": null }, { "role": "assistant", "content": "SELECT so.order_id, g.first_name, g.last_name, s.service_name, st.first_name AS staff_first_name, st.last_name AS staff_last_name, so.order_timestamp FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.staff st ON so.staff_id_delivered = st.staff_id WHERE s.category = 'spa' AND so.order_timestamp >= NOW() - INTERVAL '1 month';", "sql": null }, { "role": "user", "content": "Now, include only orders with a total price over $100.", "sql": null }, { "role": "assistant", "content": "SELECT so.order_id, g.first_name, g.last_name, s.service_name, st.first_name AS staff_first_name, st.last_name AS staff_last_name, so.order_timestamp, so.total_price FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.staff st ON so.staff_id_delivered = st.staff_id WHERE s.category = 'spa' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100;", "sql": null }, { "role": "user", "content": "The query is missing the property name. Can you include that as well?", "sql": null }, { "role": "assistant", "content": "SELECT so.order_id, g.first_name, g.last_name, p.property_name, s.service_name, st.first_name AS staff_first_name, st.last_name AS staff_last_name, so.order_timestamp, so.total_price FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.staff st ON so.staff_id_delivered = st.staff_id JOIN hospitality_technology.properties p ON so.property_id = p.property_id WHERE s.category = 'spa' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100;", "sql": null }, { "role": "user", "content": "Actually, I need to see the reservation ID and check-in date for these orders too, and order by total price in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT so.order_id, g.first_name, g.last_name, p.property_name, s.service_name, st.first_name AS staff_first_name, st.last_name AS staff_last_name, r.reservation_id, r.check_in_date, so.order_timestamp, so.total_price FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.staff st ON so.staff_id_delivered = st.staff_id JOIN hospitality_technology.properties p ON so.property_id = p.property_id JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE s.category = 'spa' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100 ORDER BY so.total_price DESC;", "sql": null }, { "role": "user", "content": "Show me all staff members along with their positions and the names of the properties they work at.", "sql": null }, { "role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id;", "sql": null }, { "role": "user", "content": "Only include staff who are not currently active.", "sql": null }, { "role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.is_active = FALSE;", "sql": null }, { "role": "user", "content": "For each reservation, show the guest's first and last name, the property name, and the names of all services ordered during that reservation.", "sql": null }, { "role": "assistant", "content": "SELECT r.reservation_id, g.first_name, g.last_name, p.property_name, s.service_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nJOIN hospitality_technology.service_orders so ON r.reservation_id = so.reservation_id\nJOIN hospitality_technology.staff g ON r.guest_id = g.staff_id\nJOIN hospitality_technology.services s ON so.service_id = s.service_id;", "sql": null }, { "role": "user", "content": "Only include reservations where at least 3 different services were ordered, and sort by the guest's last name ascending.", "sql": null }, { "role": "assistant", "content": "SELECT r.reservation_id, g.first_name, g.last_name, p.property_name, GROUP_CONCAT(DISTINCT s.service_name) AS services_ordered\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nJOIN hospitality_technology.service_orders so ON r.reservation_id = so.reservation_id\nJOIN hospitality_technology.staff g ON r.guest_id = g.staff_id\nJOIN hospitality_technology.services s ON so.service_id = s.service_id\nGROUP BY r.reservation_id, g.first_name, g.last_name, p.property_name\nHAVING COUNT(DISTINCT s.service_id) >= 3\nORDER BY g.last_name ASC;", "sql": null }, { "role": "user", "content": "For each room, list the room number, property name, and the type name of the room.", "sql": null }, { "role": "assistant", "content": "SELECT r.room_number, p.property_name, rt.type_name\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id;", "sql": null }, { "role": "user", "content": "Only include rooms located on floor 1 or 2 with the feature 'Sea View'.", "sql": null }, { "role": "assistant", "content": "SELECT r.room_number, p.property_name, rt.type_name\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nWHERE r.floor IN (1, 2) AND r.features ILIKE '%Sea View%';", "sql": null }, { "role": "user", "content": "The SQL failed because 'ILIKE' is not supported. Please replace it with an alternative.", "sql": null }, { "role": "assistant", "content": "SELECT r.room_number, p.property_name, rt.type_name\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nWHERE r.floor IN (1, 2) AND LOWER(r.features) LIKE '%sea view%';", "sql": null }, { "role": "user", "content": "Show me the count of rooms by status.", "sql": null }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS room_count\nFROM hospitality_technology.rooms\nGROUP BY status;", "sql": null }, { "role": "user", "content": "Actually, I need that breakdown by property as well.", "sql": null }, { "role": "assistant", "content": "SELECT property_id,\n status,\n COUNT(*) AS room_count\nFROM hospitality_technology.rooms\nGROUP BY property_id, status\nORDER BY property_id, status;", "sql": null }, { "role": "user", "content": "Get me a list of all public reviews along with the guest's full name and the staff member who responded, including the overall rating and review date.", "sql": null }, { "role": "assistant", "content": "SELECT rev.review_id,\n g.first_name || ' ' || g.last_name AS guest_name,\n rev.rating_overall,\n rev.review_date,\n s.first_name || ' ' || s.last_name AS responder_name\nFROM hospitality_technology.reviews rev\nLEFT JOIN hospitality_technology.guests g ON rev.guest_id = g.guest_id\nLEFT JOIN hospitality_technology.staff s ON rev.response_staff_id = s.staff_id\nWHERE rev.is_public = TRUE;", "sql": null }, { "role": "user", "content": "Filter those to only include reviews with an overall rating above 4.", "sql": null }, { "role": "assistant", "content": "SELECT rev.review_id,\n g.first_name || ' ' || g.last_name AS guest_name,\n rev.rating_overall,\n rev.review_date,\n s.first_name || ' ' || s.last_name AS responder_name\nFROM hospitality_technology.reviews rev\nLEFT JOIN hospitality_technology.guests g ON rev.guest_id = g.guest_id\nLEFT JOIN hospitality_technology.staff s ON rev.response_staff_id = s.staff_id\nWHERE rev.is_public = TRUE\n AND rev.rating_overall > 4;", "sql": null }, { "role": "user", "content": "Also sort the results by review_date in ascending order.", "sql": null }, { "role": "assistant", "content": "SELECT rev.review_id,\n g.first_name || ' ' || g.last_name AS guest_name,\n rev.rating_overall,\n rev.review_date,\n s.first_name || ' ' || s.last_name AS responder_name\nFROM hospitality_technology.reviews rev\nLEFT JOIN hospitality_technology.guests g ON rev.guest_id = g.guest_id\nLEFT JOIN hospitality_technology.staff s ON rev.response_staff_id = s.staff_id\nWHERE rev.is_public = TRUE\n AND rev.rating_overall > 4\nORDER BY rev.review_date ASC;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )
[ { "role": "user", "content": "Show the document ID, claim ID, and file name for all documents with a MIME type starting with 'image/'.", "sql": null }, { "role": "assistant", "content": "SELECT document_id, claim_id, file_name FROM insurance.claim_documents WHERE mime_type LIKE 'image/%';", "sql": null }, { "role": "user", "content": "Can you also include the uploaded_by user and only show documents uploaded after January 1, 2023?", "sql": null }, { "role": "assistant", "content": "SELECT document_id, claim_id, file_name, uploaded_by FROM insurance.claim_documents WHERE mime_type LIKE 'image/%' AND uploaded_at >= '2023-01-01';", "sql": null }, { "role": "user", "content": "List all claim IDs that have both an 'Accident Report' and a 'Damage Assessment' document type.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id\nFROM insurance.claim_documents\nWHERE document_type IN ('Accident Report', 'Damage Assessment')\nGROUP BY claim_id\nHAVING COUNT(DISTINCT document_type) = 2;", "sql": null }, { "role": "user", "content": "This returns claim IDs even if they have only multiple 'Accident Report' entries and no 'Damage Assessment'. I want to ensure each claim_id has at least one of each type.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id\nFROM insurance.claim_documents\nGROUP BY claim_id\nHAVING SUM(CASE WHEN document_type = 'Accident Report' THEN 1 ELSE 0 END) > 0\n AND SUM(CASE WHEN document_type = 'Damage Assessment' THEN 1 ELSE 0 END) > 0;", "sql": null }, { "role": "user", "content": "Also, only include documents uploaded after '2024-01-01'.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id\nFROM insurance.claim_documents\nWHERE uploaded_at > '2024-01-01'\nGROUP BY claim_id\nHAVING SUM(CASE WHEN document_type = 'Accident Report' THEN 1 ELSE 0 END) > 0\n AND SUM(CASE WHEN document_type = 'Damage Assessment' THEN 1 ELSE 0 END) > 0;", "sql": null }, { "role": "user", "content": "Finally, sort the result by claim_id in ascending order.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id\nFROM insurance.claim_documents\nWHERE uploaded_at > '2024-01-01'\nGROUP BY claim_id\nHAVING SUM(CASE WHEN document_type = 'Accident Report' THEN 1 ELSE 0 END) > 0\n AND SUM(CASE WHEN document_type = 'Damage Assessment' THEN 1 ELSE 0 END) > 0\nORDER BY claim_id ASC;", "sql": null }, { "role": "user", "content": "How many documents exist for each document_type? Return document_type and the count.", "sql": null }, { "role": "assistant", "content": "SELECT document_type,\n COUNT(*) AS document_count\nFROM insurance.claim_documents\nGROUP BY document_type;", "sql": null }, { "role": "user", "content": "Show me all documents uploaded in 2024 that do not have a description.", "sql": null }, { "role": "assistant", "content": "SELECT document_id, file_name, uploaded_at\nFROM insurance.claim_documents\nWHERE uploaded_at >= '2024-01-01'\n AND uploaded_at < '2025-01-01'\n AND (description IS NULL OR description = '');", "sql": null }, { "role": "user", "content": "Find the claim ID and the total number of documents associated with each claim ID that has more than 10 documents.", "sql": null }, { "role": "assistant", "content": "SELECT claim_id, COUNT(*) FROM insurance.claim_documents GROUP BY claim_id HAVING COUNT(*) > 10;", "sql": null }, { "role": "user", "content": "Which document types have been used for more than 100 documents, and what is the total file size across all documents of each such type?", "sql": null }, { "role": "assistant", "content": "SELECT document_type, COUNT(*) AS document_count, SUM(file_size_bytes) AS total_file_size_bytes\nFROM insurance.claim_documents\nGROUP BY document_type\nHAVING COUNT(*) > 100;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure Index 'suppliers'. Mapping: { properties: { supplier_id: { type: 'keyword' }, supplier_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, address: { type: 'text' }, country: { type: 'keyword' }, contact_person: { type: 'text', index: false }, contact_email: { type: 'keyword' }, quality_rating: { type: 'float' }, certified_date: { type: 'date' } } }. Document _id can be supplier_id.
[ { "role": "user", "content": "특정 품질 등급 이상의 공급업체를 조회하고 싶습니다. 품질 등급, 공급업체 이름, 국가를 포함해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\"]\n}", "sql": null }, { "role": "user", "content": "특정 국가에 속한 공급업체만 추가로 필터링하고 싶습니다. 예를 들어, 일본 소속 공급업체로 제한하고 싶습니다.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n {\n \"term\": {\n \"country\": \"Japan\"\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\"]\n}", "sql": null }, { "role": "user", "content": "연락처 담당자 이름과 인증 날짜도 결과에 포함해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n {\n \"term\": {\n \"country\": \"Japan\"\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\", \"contact_person\", \"certified_date\"]\n}", "sql": null }, { "role": "user", "content": "인증 날짜를 기준으로 오름차순 정렬을 추가해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n {\n \"term\": {\n \"country\": \"Japan\"\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\", \"contact_person\", \"certified_date\"],\n \"sort\": [\n {\n \"certified_date\": {\n \"order\": \"asc\"\n }\n }\n ]\n}", "sql": null }, { "role": "user", "content": "특정 국가의 모든 공급업체 정보를 조회하고 싶습니다. 국가 이름, 공급업체 이름, 주소, 품질 등급을 포함해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\"]\n}", "sql": null }, { "role": "user", "content": "품질 등급이 3.5 이상인 공급업체만 보고 싶습니다. 어떻게 수정해야 하나요?", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\"]\n}", "sql": null }, { "role": "user", "content": "인증 날짜가 2020년 이후인 공급업체만 추가로 필터링하고 싶습니다.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n },\n {\n \"range\": {\n \"certified_date\": {\n \"gte\": \"2020-01-01\"\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\", \"certified_date\"]\n}", "sql": null }, { "role": "user", "content": "결과를 품질 등급 기준으로 내림차순 정렬해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n },\n {\n \"range\": {\n \"certified_date\": {\n \"gte\": \"2020-01-01\"\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\", \"certified_date\"],\n \"sort\": [\n {\n \"quality_rating\": {\n \"order\": \"desc\"\n }\n }\n ]\n}", "sql": null }, { "role": "user", "content": "특정 공급업체 ID로 공급업체의 세부 정보를 조회하고 싶습니다. 모든 필드를 포함해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_doc/{supplier_id}", "sql": null }, { "role": "user", "content": "만약 여러 공급업체 ID를 한 번에 조회하고 싶다면 어떻게 해야 하나요?", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"terms\": {\n \"supplier_id\": [\"id1\", \"id2\", \"id3\"]\n }\n }\n}", "sql": null }, { "role": "user", "content": "조회 결과에서 공급업체 이름과 연락처 이메일만 보고 싶습니다.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"terms\": {\n \"supplier_id\": [\"id1\", \"id2\", \"id3\"]\n }\n },\n \"_source\": [\"supplier_name\", \"contact_email\"]\n}", "sql": null }, { "role": "user", "content": "결과를 공급업체 이름 기준으로 오름차순 정렬해 주세요.", "sql": null }, { "role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"terms\": {\n \"supplier_id\": [\"id1\", \"id2\", \"id3\"]\n }\n },\n \"_source\": [\"supplier_name\", \"contact_email\"],\n \"sort\": [\n {\n \"supplier_name.keyword\": {\n \"order\": \"asc\"\n }\n }\n ]\n}", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, -- unique identifier for the loan, could be same as account_id account_id character varying(64) NOT NULL UNIQUE, -- link to the general account record loan_type character varying(50) NOT NULL, -- e.g., Mortgage, Personal, Auto, Student principal_amount numeric(19, 4) NOT NULL, -- original loan amount current_principal_balance numeric(19, 4) NOT NULL, -- remaining principal interest_rate numeric(6, 4) NOT NULL, -- annual interest rate term_months integer NOT NULL, -- loan term in months origination_date date NOT NULL, -- date the loan was disbursed maturity_date date NOT NULL, -- date the loan is due to be fully repaid monthly_payment numeric(12, 4), -- scheduled monthly payment amount collateral_description text, -- description of collateral, if secured loan status character varying(32) NOT NULL, -- e.g., Active, Paid Off, Defaulted PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )
[ { "role": "user", "content": "Retrieve all pairs of loans for the same account where both loans are active and have different loan types. Show account_id, loan_id as loan_a, loan_type as type_a, loan_id as loan_b, and loan_type as type_b.", "sql": null }, { "role": "assistant", "content": "SELECT a.account_id,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type;", "sql": null }, { "role": "user", "content": "Actually, only include pairs where loan_a has a higher principal_amount than loan_b.", "sql": null }, { "role": "assistant", "content": "SELECT a.account_id,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type\n AND a.principal_amount > b.principal_amount;", "sql": null }, { "role": "user", "content": "Now restrict to accounts where the total number of active loans is at least 3.", "sql": null }, { "role": "assistant", "content": "SELECT a.account_id,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type\n AND a.principal_amount > b.principal_amount\n AND a.account_id IN (\n SELECT account_id\n FROM financial_services.loans\n WHERE status = 'Active'\n GROUP BY account_id\n HAVING COUNT(*) >= 3\n );", "sql": null }, { "role": "user", "content": "Finally, also include the number of active loans for each account as loan_count.", "sql": null }, { "role": "assistant", "content": "WITH active_counts AS (\n SELECT account_id,\n COUNT(*) AS loan_count\n FROM financial_services.loans\n WHERE status = 'Active'\n GROUP BY account_id\n)\nSELECT a.account_id,\n ac.loan_count,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nJOIN active_counts ac\n ON a.account_id = ac.account_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type\n AND a.principal_amount > b.principal_amount\n AND ac.loan_count >= 3;", "sql": null }, { "role": "user", "content": "For each account opening year, I'd like the total principal amount of loans and the count of loans. Please join loans with accounts.", "sql": null }, { "role": "assistant", "content": "SELECT EXTRACT(YEAR FROM a.created_at) AS open_year,\n SUM(l.principal_amount) AS total_principal,\n COUNT(*) AS loan_count\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nGROUP BY open_year;", "sql": null }, { "role": "user", "content": "Actually, only include accounts whose status is 'Active'.", "sql": null }, { "role": "assistant", "content": "SELECT EXTRACT(YEAR FROM a.created_at) AS open_year,\n SUM(l.principal_amount) AS total_principal,\n COUNT(*) AS loan_count\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nWHERE a.status = 'Active'\nGROUP BY open_year;", "sql": null }, { "role": "user", "content": "Then order those years by total_principal ascending.", "sql": null }, { "role": "assistant", "content": "SELECT EXTRACT(YEAR FROM a.created_at) AS open_year,\n SUM(l.principal_amount) AS total_principal,\n COUNT(*) AS loan_count\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nWHERE a.status = 'Active'\nGROUP BY open_year\nORDER BY total_principal ASC;", "sql": null }, { "role": "user", "content": "Show me a summary per loan_type with the minimum interest_rate, maximum interest_rate, and the average current_principal_balance.", "sql": null }, { "role": "assistant", "content": "SELECT loan_type,\n MIN(interest_rate) AS min_interest_rate,\n MAX(interest_rate) AS max_interest_rate,\n AVG(current_principal_balance) AS avg_balance\nFROM financial_services.loans\nGROUP BY loan_type;", "sql": null }, { "role": "user", "content": "Only include loans that were originated on or after 2022-01-01.", "sql": null }, { "role": "assistant", "content": "SELECT loan_type,\n MIN(interest_rate) AS min_interest_rate,\n MAX(interest_rate) AS max_interest_rate,\n AVG(current_principal_balance) AS avg_balance\nFROM financial_services.loans\nWHERE origination_date >= DATE '2022-01-01'\nGROUP BY loan_type;", "sql": null }, { "role": "user", "content": "And restrict to loans with a term longer than 24 months.", "sql": null }, { "role": "assistant", "content": "SELECT loan_type,\n MIN(interest_rate) AS min_interest_rate,\n MAX(interest_rate) AS max_interest_rate,\n AVG(current_principal_balance) AS avg_balance\nFROM financial_services.loans\nWHERE origination_date >= DATE '2022-01-01'\n AND term_months > 24\nGROUP BY loan_type;", "sql": null }, { "role": "user", "content": "For each loan, calculate the number of days until maturity. Display loan_id, account_id, maturity_date, and days_to_maturity as the difference between maturity_date and CURRENT_DATE.", "sql": null }, { "role": "assistant", "content": "SELECT loan_id,\n account_id,\n maturity_date,\n (maturity_date - CURRENT_DATE) AS days_to_maturity\nFROM financial_services.loans;", "sql": null }, { "role": "user", "content": "Actually, only include loans where days_to_maturity is between 30 and 180 days.", "sql": null }, { "role": "assistant", "content": "SELECT loan_id,\n account_id,\n maturity_date,\n (maturity_date - CURRENT_DATE) AS days_to_maturity\nFROM financial_services.loans\nWHERE (maturity_date - CURRENT_DATE) BETWEEN 30 AND 180;", "sql": null }, { "role": "user", "content": "Finally, join to the accounts table to include account_type in the result.", "sql": null }, { "role": "assistant", "content": "SELECT l.loan_id,\n l.account_id,\n a.account_type,\n l.maturity_date,\n (l.maturity_date - CURRENT_DATE) AS days_to_maturity\nFROM financial_services.loans l\nJOIN financial_services.accounts a\n ON l.account_id = a.account_id\nWHERE (l.maturity_date - CURRENT_DATE) BETWEEN 30 AND 180;", "sql": null }, { "role": "user", "content": "I need a report that shows, for each account status and loan type, how many loans there are and the average principal amount.", "sql": null }, { "role": "assistant", "content": "SELECT a.status,\n l.loan_type,\n COUNT(*) AS total_loans,\n AVG(l.principal_amount) AS average_principal\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nGROUP BY a.status, l.loan_type;", "sql": null }, { "role": "user", "content": "Actually, include only loans whose status is 'Active'.", "sql": null }, { "role": "assistant", "content": "SELECT a.status,\n l.loan_type,\n COUNT(*) AS total_loans,\n AVG(l.principal_amount) AS average_principal\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nWHERE l.status = 'Active'\nGROUP BY a.status, l.loan_type;", "sql": null }, { "role": "user", "content": "Also exclude any loan_type groups that have fewer than 5 loans.", "sql": null }, { "role": "assistant", "content": "SELECT a.status,\n l.loan_type,\n COUNT(*) AS total_loans,\n AVG(l.principal_amount) AS average_principal\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nWHERE l.status = 'Active'\nGROUP BY a.status, l.loan_type\nHAVING COUNT(*) >= 5;", "sql": null }, { "role": "user", "content": "Finally, sort the output by average_principal in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT a.status,\n l.loan_type,\n COUNT(*) AS total_loans,\n AVG(l.principal_amount) AS average_principal\nFROM financial_services.loans l\nJOIN financial_services.accounts a ON l.account_id = a.account_id\nWHERE l.status = 'Active'\nGROUP BY a.status, l.loan_type\nHAVING COUNT(*) >= 5\nORDER BY average_principal DESC;", "sql": null }, { "role": "user", "content": "List all auto loans (loan_id, principal_amount, interest_rate) where the current principal balance is less than 40% of the original principal amount, along with the account_id and the difference between principal_amount and current_principal_balance.", "sql": null }, { "role": "assistant", "content": "SELECT loan_id, principal_amount, interest_rate, account_id, (principal_amount - current_principal_balance) AS amount_paid FROM financial_services.loans WHERE loan_type = 'Auto' AND current_principal_balance < (0.4 * principal_amount);", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text ) CREATE TABLE legal_services.lawyers ( lawyer_id text, first_name text, last_name text, bar_number text, firm_id text, email text, phone text, specialization text, hire_date timestamp, is_partner boolean ) CREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text ) CREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text ) CREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp ) CREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )
[ { "role": "user", "content": "List all appointments along with their subject and start time for lawyers specializing in 'Criminal Law'.", "sql": null }, { "role": "assistant", "content": "SELECT T1.subject, T1.start_time FROM legal_services.appointments AS T1 JOIN legal_services.lawyers AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.specialization = 'Criminal Law';", "sql": null }, { "role": "user", "content": "Could you please list the first and last names of all clients?", "sql": null }, { "role": "assistant", "content": "SELECT first_name, last_name FROM clients;", "sql": null }, { "role": "user", "content": "Now, only show clients whose status is 'active'.", "sql": null }, { "role": "assistant", "content": "SELECT first_name, last_name FROM clients WHERE status = 'active';", "sql": null }, { "role": "user", "content": "Please include their email address in the results as well.", "sql": null }, { "role": "assistant", "content": "SELECT first_name, last_name, email FROM clients WHERE status = 'active';", "sql": null }, { "role": "user", "content": "Finally, order the list by the client's last name.", "sql": null }, { "role": "assistant", "content": "SELECT first_name, last_name, email FROM clients WHERE status = 'active' ORDER BY last_name;", "sql": null }, { "role": "user", "content": "Show the first name, last name, and firm name for all lawyers specializing in 'Intellectual Property'.", "sql": null }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM legal_services.lawyers AS T1 JOIN legal_services.law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.specialization = 'Intellectual Property';", "sql": null }, { "role": "user", "content": "From this list, only show lawyers from firms founded after 2005.", "sql": null }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM legal_services.lawyers AS T1 JOIN legal_services.law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.specialization = 'Intellectual Property' AND T2.founded_date > '2005-12-31';", "sql": null }, { "role": "user", "content": "Also, include their hire date and sort the results by hire date ascending.", "sql": null }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name, T1.hire_date FROM legal_services.lawyers AS T1 JOIN legal_services.law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.specialization = 'Intellectual Property' AND T2.founded_date > '2005-12-31' ORDER BY T1.hire_date ASC;", "sql": null }, { "role": "user", "content": "I need a list showing the name of each law firm and the full name of every lawyer employed by that firm.", "sql": null }, { "role": "assistant", "content": "SELECT T1.firm_name, T2.first_name, T2.last_name FROM law_firms AS T1 JOIN lawyers AS T2 ON T1.firm_id = T2.firm_id;", "sql": null }, { "role": "user", "content": "Show me all time entries where the hours spent is greater than 5.", "sql": null }, { "role": "assistant", "content": "SELECT entry_id, date_worked, hours_spent, description FROM legal_services.time_entries WHERE hours_spent > 5;", "sql": null }, { "role": "user", "content": "List all documents along with the case number they are associated with, as well as the name and email of the lawyer who uploaded them.", "sql": null }, { "role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id;", "sql": null }, { "role": "user", "content": "Only include documents uploaded after April 1st, 2024.", "sql": null }, { "role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01';", "sql": null }, { "role": "user", "content": "Add the case name and make sure only documents with version greater than 1 are listed.", "sql": null }, { "role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.cases c ON d.case_id = c.case_id JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01' AND d.version > 1;", "sql": null }, { "role": "user", "content": "Order the results by upload_timestamp ascending.", "sql": null }, { "role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email, d.upload_timestamp FROM legal_services.documents d JOIN legal_services.cases c ON d.case_id = c.case_id JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01' AND d.version > 1 ORDER BY d.upload_timestamp ASC;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure // Use Hashes for platform details. Key format: platform:<platform_id> // HSET platform:plat_123 platform_id "plat_123" station_id "station_xyz" platform_number "1A" track_number "T1" status "Operational" length_meters 250.50 accessible 1 // To link platforms to stations (optional): // SADD station:station_xyz:platforms platform:plat_123 platform:plat_456 // Use Hashes for train details. Key format: train:<train_id> // HSET train:train_789 train_id "train_789" train_number "Acela 2151" model "Siemens Velaro" ... status "Active" ... // To find train by train_number (optional index): // SET train_number:"Acela 2151" train:train_789 // Use Hashes for car details. Key format: car:<car_id> // HSET car:car_abc car_id "car_abc" train_id "train_789" car_number "C3" car_type "Passenger" class "Business" capacity 60 features "WiFi,Power Outlet" // To link cars to trains (optional): // SADD train:train_789:cars car:car_abc car:car_def // Use Hashes for details. Key format: route_station:<route_station_id> // HSET route_station:rs_ne_1 route_station_id "rs_ne_1" route_id "route_ne_corr" station_id "station_bos" sequence_order 1 ... // To find stops for a route, use a Sorted Set (score by sequence_order): // ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1 // ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2 // Use Hashes for schedule details. Key format: schedule:<schedule_id> // HSET schedule:sched_1122 schedule_id "sched_1122" train_id "train_789" route_id "route_ne_corr" departure_datetime "2024-05-10T08:00:00-04:00" ... status "Scheduled" // Use Hashes for details. Key format: schedule_stop:<stop_id> // HSET schedule_stop:stop_sched1122_1 stop_id "stop_sched1122_1" schedule_id "sched_1122" station_id "station_bos" ... // To find stops for a schedule, use a Sorted Set (score by sequence_order): // ZADD schedule:sched_1122:stops 1 schedule_stop:stop_sched1122_1 // ZADD schedule:sched_1122:stops 2 schedule_stop:stop_sched1122_2 // Use Hashes for passenger details. Key format: passenger:<passenger_id> // HSET passenger:pass_pqr passenger_id "pass_pqr" first_name "Alice" last_name "Smith" email "alice.smith@example.com" ... // To find passenger by email (optional index): // SET passenger_email:"alice.smith@example.com" passenger:pass_pqr // Use Hashes for booking details. Key format: booking:<booking_id> // HSET booking:book_zyx booking_id "book_zyx" passenger_id "pass_pqr" schedule_id "sched_1122" ... status "Confirmed" ... // To link bookings to passengers/schedules (optional): // SADD passenger:pass_pqr:bookings booking:book_zyx // SADD schedule:sched_1122:bookings booking:book_zyx // Use Hashes for ticket details. Key format: ticket:<ticket_id> // HSET ticket:tkt_1a2b ticket_id "tkt_1a2b" booking_id "book_zyx" car_id "car_abc" seat_number "12A" ... is_checked_in 0 ... // To link tickets to bookings (optional): // SADD booking:book_zyx:tickets ticket:tkt_1a2b // Use Hashes for staff details. Key format: staff:<staff_id> // HSET staff:staff_mno staff_id "staff_mno" first_name "Bob" ... employee_number "E12345" ... is_active 1 // To find staff by employee number (optional index): // SET staff_employee_number:"E12345" staff:staff_mno // Use Hashes for maintenance record details. Key format: maintenance_record:<record_id> // HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed" // To link records to assets (optional): // SADD train:train_789:maintenance maintenance_record:maint_rec_001 // SADD platform:plat_123:maintenance maintenance_record:maint_rec_002
[ { "role": "user", "content": "Can you help me retrieve the details of all schedules for a specific train with train_id 'train_789', including the route and stops information?", "sql": null }, { "role": "assistant", "content": "HGETALL train:train_789\nSMEMBERS schedule:sched_*:train:train_789\nHGETALL schedule:sched_*\nHGETALL route:route_*\nZRANGE schedule:sched_*:stops 0 -1\nHGETALL schedule_stop:stop_*", "sql": null }, { "role": "user", "content": "Can you filter the schedules to only include those with a status of 'Scheduled'?", "sql": null }, { "role": "assistant", "content": "HGETALL train:train_789\nSMEMBERS schedule:sched_*:train:train_789\nHGETALL schedule:sched_*\nHGET schedule:sched_* status\nIF status == 'Scheduled' THEN\nHGETALL route:route_*\nZRANGE schedule:sched_*:stops 0 -1\nHGETALL schedule_stop:stop_*\nENDIF", "sql": null }, { "role": "user", "content": "Can you also include the departure datetime for each schedule in the result?", "sql": null }, { "role": "assistant", "content": "HGETALL train:train_789\nSMEMBERS schedule:sched_*:train:train_789\nHGETALL schedule:sched_*\nHGET schedule:sched_* status\nHGET schedule:sched_* departure_datetime\nIF status == 'Scheduled' THEN\nHGETALL route:route_*\nZRANGE schedule:sched_*:stops 0 -1\nHGETALL schedule_stop:stop_*\nENDIF", "sql": null }, { "role": "user", "content": "I need to find all bookings for a specific schedule with schedule_id 'sched_1122' and include the passenger and ticket details.", "sql": null }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGETALL ticket:tkt_*", "sql": null }, { "role": "user", "content": "Can you filter the tickets to show only those that are not checked in?", "sql": null }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nENDIF", "sql": null }, { "role": "user", "content": "Can you also include the car details for each ticket?", "sql": null }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nHGET ticket:tkt_* car_id\nHGETALL car:car_*\nENDIF", "sql": null }, { "role": "user", "content": "Can you provide the total number of cars associated with a specific train with train_id 'train_789'?", "sql": null }, { "role": "assistant", "content": "SCARD train:train_789:cars", "sql": null }, { "role": "user", "content": "能否帮我统计特定车站(station_id 为 'station_xyz')的所有平台数量?", "sql": null }, { "role": "assistant", "content": "SCARD station:station_xyz:platforms", "sql": null }, { "role": "user", "content": "能否帮我查询特定路线(route_id 为 'route_ne_corr')上的所有车站信息,并包含每个车站的平台数量?", "sql": null }, { "role": "assistant", "content": "ZRANGE route:route_ne_corr:stops 0 -1\nHGETALL route_station:<route_station_id> for each route_station_id in result\nHGETALL station:<station_id> for each station_id in result\nSCARD station:<station_id>:platforms for each station_id in result", "sql": null }, { "role": "user", "content": "能否将结果按照车站的顺序(sequence_order)进行排序?", "sql": null }, { "role": "assistant", "content": "ZRANGE route:route_ne_corr:stops 0 -1 WITHSCORES\nHGETALL route_station:<route_station_id> for each route_station_id in result\nHGETALL station:<station_id> for each station_id in result\nSCARD station:<station_id>:platforms for each station_id in result\nSort results by sequence_order (score from ZRANGE)", "sql": null }, { "role": "user", "content": "能否只显示有超过5个平台的车站信息?", "sql": null }, { "role": "assistant", "content": "ZRANGE route:route_ne_corr:stops 0 -1 WITHSCORES\nHGETALL route_station:<route_station_id> for each route_station_id in result\nHGETALL station:<station_id> for each station_id in result\nSCARD station:<station_id>:platforms for each station_id in result\nFilter results where SCARD result > 5\nSort results by sequence_order (score from ZRANGE)", "sql": null }, { "role": "user", "content": "能否帮我查询特定列车(train_id 为 'train_789')上的所有车辆信息,并关联到该列车所在的路线信息?", "sql": null }, { "role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car:<car_id> for each car_id in result\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking:<booking_id> for each booking_id in result\nHGETALL route:<route_id> for route_id associated with schedule", "sql": null }, { "role": "user", "content": "能否将查询结果限制在车辆类型为‘Passenger’的车辆上?", "sql": null }, { "role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car:<car_id> for each car_id in result where car_type='Passenger'\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking:<booking_id> for each booking_id in result\nHGETALL route:<route_id> for route_id associated with schedule", "sql": null }, { "role": "user", "content": "能否再加入车辆的座位容量信息,并按照容量从大到小排序?", "sql": null }, { "role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car:<car_id> for each car_id in result where car_type='Passenger'\nSORT car:<car_id> BY capacity DESC\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking:<booking_id> for each booking_id in result\nHGETALL route:<route_id> for route_id associated with schedule", "sql": null }, { "role": "user", "content": "能否也把路线的起点站和终点站信息加入到结果中?", "sql": null }, { "role": "assistant", "content": "SMEMBERS train:train_789:cars\nHGETALL car:<car_id> for each car_id in result where car_type='Passenger'\nSORT car:<car_id> BY capacity DESC\nHGETALL train:train_789\nSMEMBERS schedule:sched_1122:bookings\nHGETALL booking:<booking_id> for each booking_id in result\nHGETALL route:<route_id> for route_id associated with schedule\nZRANGE route:<route_id>:stops 0 0 for origin_station_id\nZRANGE route:<route_id>:stops -1 -1 for destination_station_id\nHGETALL station:<origin_station_id>\nHGETALL station:<destination_station_id>", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text ) CREATE TABLE insurance.insurance_products ( product_id text, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )
[ { "role": "user", "content": "Retrieve the policy_number, start_date, end_date, premium_amount, and corresponding product_name for policies with a coverage_limit greater than 500000.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.start_date, p.end_date, p.premium_amount, ip.product_name\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.coverage_limit > 500000;", "sql": null }, { "role": "user", "content": "List policy_number, customer_id, and product_name for policies that are currently active.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.customer_id, ip.product_name\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'Active' AND ip.is_active = true;", "sql": null }, { "role": "user", "content": "Actually, only show those policies that will expire within the next 30 days.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.customer_id, ip.product_name\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'Active'\n AND ip.is_active = true\n AND p.end_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days';", "sql": null }, { "role": "user", "content": "Also, include the product_type and only for products of type 'Life'.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.customer_id, ip.product_name, ip.product_type\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'Active'\n AND ip.is_active = true\n AND p.end_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days'\n AND ip.product_type = 'Life';", "sql": null }, { "role": "user", "content": "Sort the final results by end_date ascending, please.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.customer_id, ip.product_name, ip.product_type, p.end_date\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'Active'\n AND ip.is_active = true\n AND p.end_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days'\n AND ip.product_type = 'Life'\nORDER BY p.end_date ASC;", "sql": null }, { "role": "user", "content": "List the product_id, product_name, and base_premium for all products that are currently inactive.", "sql": null }, { "role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE is_active = false;", "sql": null }, { "role": "user", "content": "Show me all insurance products of type 'Travel', including their product_id, product_name, and base_premium.", "sql": null }, { "role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE product_type = 'Travel';", "sql": null }, { "role": "user", "content": "Which policies have a premium amount greater than the base premium of their respective insurance product? Please show the policy_number, premium_amount, product_name, and base_premium.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium;", "sql": null }, { "role": "user", "content": "Now, only include policies where the coverage_limit is above 500,000.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium\n AND p.coverage_limit > 500000;", "sql": null }, { "role": "user", "content": "Actually, I also want to see only active policies.", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium\n AND p.coverage_limit > 500000\n AND p.status = 'Active';", "sql": null }, { "role": "user", "content": "Could you sort the results by premium_amount in descending order?", "sql": null }, { "role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium\n AND p.coverage_limit > 500000\n AND p.status = 'Active'\nORDER BY p.premium_amount DESC;", "sql": null }, { "role": "user", "content": "List active policies where the premium amount is greater than the base premium of the linked insurance product. Show policy number, policy premium, product name, and product base premium.", "sql": null }, { "role": "assistant", "content": "SELECT T1.policy_number, T1.premium_amount, T2.product_name, T2.base_premium FROM insurance.policies AS T1 JOIN insurance.insurance_products AS T2 ON T1.product_id = T2.product_id WHERE T1.status = 'active' AND T1.premium_amount > T2.base_premium;", "sql": null }, { "role": "user", "content": "Also, only include policies that were issued in the year 2023.", "sql": null }, { "role": "assistant", "content": "SELECT T1.policy_number, T1.premium_amount, T2.product_name, T2.base_premium FROM insurance.policies AS T1 JOIN insurance.insurance_products AS T2 ON T1.product_id = T2.product_id WHERE T1.status = 'active' AND T1.premium_amount > T2.base_premium AND EXTRACT(YEAR FROM T1.issued_at) = 2023;", "sql": null }, { "role": "user", "content": "Could you sort the results by policy premium in descending order and limit to the top 10?", "sql": null }, { "role": "assistant", "content": "SELECT T1.policy_number, T1.premium_amount, T2.product_name, T2.base_premium FROM insurance.policies AS T1 JOIN insurance.insurance_products AS T2 ON T1.product_id = T2.product_id WHERE T1.status = 'active' AND T1.premium_amount > T2.base_premium AND EXTRACT(YEAR FROM T1.issued_at) = 2023 ORDER BY T1.premium_amount DESC LIMIT 10;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )
[ { "role": "user", "content": "Find all pairs of tokens that have the same contract_address but different token_symbols. Show both token_ids, each token's symbol, and the shared contract_address.", "sql": null }, { "role": "assistant", "content": "SELECT t1.token_id AS token_id_1, t2.token_id AS token_id_2, t1.token_symbol AS symbol_1, t2.token_symbol AS symbol_2, t1.contract_address FROM web3.tokens t1 JOIN web3.tokens t2 ON t1.contract_address = t2.contract_address AND t1.token_id < t2.token_id AND t1.token_symbol <> t2.token_symbol;", "sql": null }, { "role": "user", "content": "List all tokens along with the contract addresses for symbols that appear more than once.", "sql": null }, { "role": "assistant", "content": "SELECT t.token_id, t.token_symbol, t.contract_address\nFROM web3.tokens t\nJOIN (\n SELECT token_symbol\n FROM web3.tokens\n GROUP BY token_symbol\n HAVING COUNT(*) > 1\n) dup ON t.token_symbol = dup.token_symbol;", "sql": null }, { "role": "user", "content": "What is the average total_supply for each decimals value?", "sql": null }, { "role": "assistant", "content": "SELECT decimals, AVG(total_supply) AS avg_supply\nFROM web3.tokens\nGROUP BY decimals;", "sql": null }, { "role": "user", "content": "Actually, I only want to include tokens whose token_symbol starts with 'A'.", "sql": null }, { "role": "assistant", "content": "SELECT decimals, AVG(total_supply) AS avg_supply\nFROM web3.tokens\nWHERE token_symbol LIKE 'A%'\nGROUP BY decimals;", "sql": null }, { "role": "user", "content": "Show all tokens where the total_supply is less than 10000, listing the token_id, token_symbol, and decimals.", "sql": null }, { "role": "assistant", "content": "SELECT token_id, token_symbol, decimals FROM web3.tokens WHERE total_supply < 10000;", "sql": null }, { "role": "user", "content": "Actually, please also include the token_name in the result and order the results by total_supply ascending.", "sql": null }, { "role": "assistant", "content": "SELECT token_id, token_symbol, token_name, decimals FROM web3.tokens WHERE total_supply < 10000 ORDER BY total_supply ASC;", "sql": null }, { "role": "user", "content": "Show me the token names and their contract addresses where the total supply is greater than 1 million, sorted by total supply in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT token_name, contract_address FROM web3.tokens WHERE total_supply > 1000000 ORDER BY total_supply DESC;", "sql": null }, { "role": "user", "content": "List all pairs of tokens (show token_id for both) that share the same contract address, excluding pairs where the token_id is the same.", "sql": null }, { "role": "assistant", "content": "SELECT t1.token_id AS token_id1, t2.token_id AS token_id2, t1.contract_address FROM web3.tokens AS t1 JOIN web3.tokens AS t2 ON t1.contract_address = t2.contract_address WHERE t1.token_id < t2.token_id;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )
[ { "role": "user", "content": "List all tokens with a price below $1 and a 24-hour trading volume over $5 million.", "sql": null }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume FROM token_basic_info WHERE price < 1 AND total_volume::numeric > 5000000;", "sql": null }, { "role": "user", "content": "Show tokens with a trend rank worse than 30 (higher number) that also have a positive price change over the last 24 hours. Display their symbol, chain, price, trend rank, and 24h price change.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, price, trend_rank, price_change_percentage_24h FROM token_basic_info WHERE trend_rank > 30 AND price_change_percentage_24h > 0", "sql": null }, { "role": "user", "content": "Only show results for tokens on the 'Ethereum' chain.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, price, trend_rank, price_change_percentage_24h FROM token_basic_info WHERE trend_rank > 30 AND price_change_percentage_24h > 0 AND chain = 'Ethereum'", "sql": null }, { "role": "user", "content": "Also filter for tokens with a market cap greater than $100,000,000.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, price, trend_rank, price_change_percentage_24h FROM token_basic_info WHERE trend_rank > 30 AND price_change_percentage_24h > 0 AND chain = 'Ethereum' AND market_cap > 100000000", "sql": null }, { "role": "user", "content": "Order the results by 24-hour price change percentage descending and show the top 10.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, price, trend_rank, price_change_percentage_24h FROM token_basic_info WHERE trend_rank > 30 AND price_change_percentage_24h > 0 AND chain = 'Ethereum' AND market_cap > 100000000 ORDER BY price_change_percentage_24h DESC LIMIT 10", "sql": null }, { "role": "user", "content": "For the 'DeFi' narrative, what is the average price, average market cap, and average 24-hour trading volume of its tokens?", "sql": null }, { "role": "assistant", "content": "SELECT AVG(price) AS avg_price, AVG(market_cap) AS avg_market_cap, AVG(CAST(total_volume AS DOUBLE PRECISION)) AS avg_total_volume FROM token_basic_info WHERE narrative = 'DeFi'", "sql": null }, { "role": "user", "content": "Instead of just 'DeFi', show these average metrics (price, market cap, 24h volume) for *all* narratives.", "sql": null }, { "role": "assistant", "content": "SELECT narrative, AVG(price) AS avg_price, AVG(market_cap) AS avg_market_cap, AVG(CAST(total_volume AS DOUBLE PRECISION)) AS avg_total_volume FROM token_basic_info WHERE narrative IS NOT NULL GROUP BY narrative", "sql": null }, { "role": "user", "content": "Only include narratives with at least 10 tokens and an average market cap above $500,000,000. Order the results by average market cap descending and show the top 5.", "sql": null }, { "role": "assistant", "content": "SELECT narrative, AVG(price) AS avg_price, AVG(market_cap) AS avg_market_cap, AVG(CAST(total_volume AS DOUBLE PRECISION)) AS avg_total_volume FROM token_basic_info WHERE narrative IS NOT NULL GROUP BY narrative HAVING COUNT(*) >= 10 AND AVG(market_cap) > 500000000 ORDER BY avg_market_cap DESC LIMIT 5", "sql": null }, { "role": "user", "content": "Also include the average trend rank for each of these narratives.", "sql": null }, { "role": "assistant", "content": "SELECT narrative, AVG(price) AS avg_price, AVG(market_cap) AS avg_market_cap, AVG(CAST(total_volume AS DOUBLE PRECISION)) AS avg_total_volume, AVG(trend_rank) AS avg_trend_rank FROM token_basic_info WHERE narrative IS NOT NULL GROUP BY narrative HAVING COUNT(*) >= 10 AND AVG(market_cap) > 500000000 ORDER BY avg_market_cap DESC LIMIT 5", "sql": null }, { "role": "user", "content": "Show me the top 3 tokens by trend rank in the 'NFT' narrative, along with their price and 24-hour trading volume.", "sql": null }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume FROM token_basic_info WHERE narrative = 'NFT' ORDER BY trend_rank ASC LIMIT 3;", "sql": null }, { "role": "user", "content": "Can you also include their 1-hour and 7-day price change percentages?", "sql": null }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume, price_change_percentage_1h, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' ORDER BY trend_rank ASC LIMIT 3;", "sql": null }, { "role": "user", "content": "Actually, I only want tokens with positive price changes in both time frames.", "sql": null }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume, price_change_percentage_1h, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' AND price_change_percentage_1h > 0 AND price_change_percentage_7d > 0 ORDER BY trend_rank ASC LIMIT 3;", "sql": null }, { "role": "user", "content": "Now order the results by 24-hour trading volume instead of trend rank.", "sql": null }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume, price_change_percentage_1h, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' AND price_change_percentage_1h > 0 AND price_change_percentage_7d > 0 ORDER BY total_volume::numeric DESC LIMIT 3;", "sql": null }, { "role": "user", "content": "List the top 5 tokens by price_change_percentage_7d, showing token_symbol, narrative, and price_change_percentage_7d.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, narrative, price_change_percentage_7d\nFROM token_basic_info\nORDER BY price_change_percentage_7d DESC\nLIMIT 5;", "sql": null }, { "role": "user", "content": "List tokens that have a 24-hour trading volume greater than $10,000,000 and a negative price change percentage over the last 24 hours. Show the token symbol, chain, total volume, and the 24-hour price change percentage.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, total_volume, price_change_percentage_24h FROM token_basic_info WHERE CAST(REPLACE(total_volume, ',', '') AS numeric) > 10000000 AND price_change_percentage_24h < 0", "sql": null }, { "role": "user", "content": "From those results, filter further to only include tokens with a market cap rank of 100 or better. Order the results by 24-hour trading volume in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT token_symbol, chain, total_volume, price_change_percentage_24h FROM token_basic_info WHERE CAST(REPLACE(total_volume, ',', '') AS numeric) > 10000000 AND price_change_percentage_24h < 0 AND market_cap_rank IS NOT NULL AND market_cap_rank <= 100 ORDER BY CAST(REPLACE(total_volume, ',', '') AS numeric) DESC", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )
[ { "role": "user", "content": "Show a count of drivers per status.", "sql": null }, { "role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count\nFROM transportation.drivers\nGROUP BY status;", "sql": null }, { "role": "user", "content": "Can you also list the earliest hire date for each status?", "sql": null }, { "role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count, MIN(hire_date) AS earliest_hire_date\nFROM transportation.drivers\nGROUP BY status;", "sql": null }, { "role": "user", "content": "I only want to see statuses with more than 5 drivers.", "sql": null }, { "role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count, MIN(hire_date) AS earliest_hire_date\nFROM transportation.drivers\nGROUP BY status\nHAVING COUNT(*) > 5;", "sql": null }, { "role": "user", "content": "Please sort the output by driver_count in descending order.", "sql": null }, { "role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count, MIN(hire_date) AS earliest_hire_date\nFROM transportation.drivers\nGROUP BY status\nHAVING COUNT(*) > 5\nORDER BY driver_count DESC;", "sql": null }, { "role": "user", "content": "Calculate the total number of drivers for each status.", "sql": null }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS driver_count\nFROM transportation.drivers\nGROUP BY status;", "sql": null }, { "role": "user", "content": "Now only include statuses with more than 10 drivers.", "sql": null }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS driver_count\nFROM transportation.drivers\nGROUP BY status\nHAVING COUNT(*) > 10;", "sql": null }, { "role": "user", "content": "List all drivers whose licenses are set to expire within the next 60 days, along with their full name, license number, and contact number.", "sql": null }, { "role": "assistant", "content": "SELECT driver_id, first_name, last_name, license_number, contact_number\nFROM transportation.drivers\nWHERE license_expiry_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '60 days';", "sql": null }, { "role": "user", "content": "For each driver, show their driver_id, first_name, last_name, along with any other driver whose license_expiry_date is earlier than theirs.", "sql": null }, { "role": "assistant", "content": "SELECT d1.driver_id AS driver_id,\n d1.first_name,\n d1.last_name,\n d2.driver_id AS earlier_driver_id,\n d2.license_expiry_date AS earlier_expiry_date\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date < d1.license_expiry_date;", "sql": null }, { "role": "user", "content": "Exclude pairs where the two expiry dates are not in the same calendar year.", "sql": null }, { "role": "assistant", "content": "SELECT d1.driver_id AS driver_id,\n d1.first_name,\n d1.last_name,\n d2.driver_id AS earlier_driver_id,\n d2.license_expiry_date AS earlier_expiry_date\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date < d1.license_expiry_date\n AND EXTRACT(YEAR FROM d1.license_expiry_date) = EXTRACT(YEAR FROM d2.license_expiry_date);", "sql": null }, { "role": "user", "content": "Also only include pairs where the difference between their expiry dates is more than 30 days.", "sql": null }, { "role": "assistant", "content": "SELECT d1.driver_id AS driver_id,\n d1.first_name,\n d1.last_name,\n d2.driver_id AS earlier_driver_id,\n d2.license_expiry_date AS earlier_expiry_date,\n DATE_PART('day', d1.license_expiry_date - d2.license_expiry_date) AS days_difference\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date < d1.license_expiry_date\n AND EXTRACT(YEAR FROM d1.license_expiry_date) = EXTRACT(YEAR FROM d2.license_expiry_date)\nWHERE d1.license_expiry_date - d2.license_expiry_date > INTERVAL '30 days';", "sql": null }, { "role": "user", "content": "List pairs of drivers whose license expiry dates fall within 30 days of each other. Show both driver_ids, names, and the two expiry dates.", "sql": null }, { "role": "assistant", "content": "SELECT d1.driver_id AS driver1_id, d1.first_name AS driver1_first, d1.last_name AS driver1_last, d1.license_expiry_date AS expiry1, d2.driver_id AS driver2_id, d2.first_name AS driver2_first, d2.last_name AS driver2_last, d2.license_expiry_date AS expiry2 FROM transportation.drivers d1 JOIN transportation.drivers d2 ON d1.driver_id < d2.driver_id AND ABS((d1.license_expiry_date - d2.license_expiry_date)) <= INTERVAL '30 days';", "sql": null }, { "role": "user", "content": "Which drivers have licenses expiring before 2025-01-01, and what are their first and last names along with the license expiry date?", "sql": null }, { "role": "assistant", "content": "SELECT driver_id, first_name, last_name, license_expiry_date FROM transportation.drivers WHERE license_expiry_date < '2025-01-01';", "sql": null }, { "role": "user", "content": "From this list, only include drivers whose status is 'Active'.", "sql": null }, { "role": "assistant", "content": "SELECT driver_id, first_name, last_name, license_expiry_date FROM transportation.drivers WHERE license_expiry_date < '2025-01-01' AND status = 'Active';", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )
[ { "role": "user", "content": "For each location, what is the average appointment duration? Show location_id and the average duration.", "sql": null }, { "role": "assistant", "content": "SELECT location_id, AVG(duration_minutes) FROM healthcare.appointments GROUP BY location_id;", "sql": null }, { "role": "user", "content": "Show all appointments that have 'follow-up' mentioned in the notes field.", "sql": null }, { "role": "assistant", "content": "SELECT * FROM healthcare.appointments WHERE notes LIKE '%follow-up%';", "sql": null }, { "role": "user", "content": "For each patient, find the next appointment after each one. Return patient_id, appointment_id AS current_appointment, next_appointment_id, and waiting_time in minutes.", "sql": null }, { "role": "assistant", "content": "SELECT a.patient_id,\n a.appointment_id AS current_appointment,\n b.appointment_id AS next_appointment_id,\n EXTRACT(EPOCH FROM (b.appointment_time - a.appointment_time)) / 60 AS waiting_time\nFROM healthcare.appointments a\nJOIN healthcare.appointments b\n ON a.patient_id = b.patient_id\n AND b.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = a.patient_id\n AND appointment_time > a.appointment_time\n ) ;", "sql": null }, { "role": "user", "content": "Only include waiting times less than 30 minutes.", "sql": null }, { "role": "assistant", "content": "SELECT a.patient_id,\n a.appointment_id AS current_appointment,\n b.appointment_id AS next_appointment_id,\n EXTRACT(EPOCH FROM (b.appointment_time - a.appointment_time)) / 60 AS waiting_time\nFROM healthcare.appointments a\nJOIN healthcare.appointments b\n ON a.patient_id = b.patient_id\n AND b.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = a.patient_id\n AND appointment_time > a.appointment_time\n )\nWHERE EXTRACT(EPOCH FROM (b.appointment_time - a.appointment_time)) / 60 < 30;", "sql": null }, { "role": "user", "content": "Get the total number of appointments grouped by status.", "sql": null }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS appointment_count\nFROM healthcare.appointments\nGROUP BY status;", "sql": null }, { "role": "user", "content": "Now filter to include only statuses with more than 50 appointments.", "sql": null }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS appointment_count\nFROM healthcare.appointments\nGROUP BY status\nHAVING COUNT(*) > 50;", "sql": null }, { "role": "user", "content": "Find overlapping appointments for each doctor. Return doctor_id, appointment_id_1, appointment_id_2, and overlap duration in minutes.", "sql": null }, { "role": "assistant", "content": "SELECT a.doctor_id,\n a.appointment_id AS appointment_id_1,\n b.appointment_id AS appointment_id_2,\n EXTRACT(EPOCH FROM (LEAST(a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes),\n b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes))\n - GREATEST(a.appointment_time, b.appointment_time))) / 60 AS overlap_minutes\nFROM healthcare.appointments a\nJOIN healthcare.appointments b\n ON a.doctor_id = b.doctor_id\n AND a.appointment_id < b.appointment_id\nWHERE a.appointment_time < b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes)\n AND b.appointment_time < a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes);", "sql": null }, { "role": "user", "content": "Exclude overlaps less than 15 minutes.", "sql": null }, { "role": "assistant", "content": "SELECT a.doctor_id,\n a.appointment_id AS appointment_id_1,\n b.appointment_id AS appointment_id_2,\n EXTRACT(EPOCH FROM (LEAST(a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes),\n b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes))\n - GREATEST(a.appointment_time, b.appointment_time))) / 60 AS overlap_minutes\nFROM healthcare.appointments a\nJOIN healthcare.appointments b\n ON a.doctor_id = b.doctor_id\n AND a.appointment_id < b.appointment_id\nWHERE a.appointment_time < b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes)\n AND b.appointment_time < a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes)\nHAVING (EXTRACT(EPOCH FROM (LEAST(a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes),\n b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes))\n - GREATEST(a.appointment_time, b.appointment_time))) / 60) >= 15;", "sql": null }, { "role": "user", "content": "Also only include overlaps where status is 'Scheduled' for both appointments.", "sql": null }, { "role": "assistant", "content": "SELECT a.doctor_id,\n a.appointment_id AS appointment_id_1,\n b.appointment_id AS appointment_id_2,\n EXTRACT(EPOCH FROM (LEAST(a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes),\n b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes))\n - GREATEST(a.appointment_time, b.appointment_time))) / 60 AS overlap_minutes\nFROM healthcare.appointments a\nJOIN healthcare.appointments b\n ON a.doctor_id = b.doctor_id\n AND a.appointment_id < b.appointment_id\nWHERE a.status = 'Scheduled'\n AND b.status = 'Scheduled'\n AND a.appointment_time < b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes)\n AND b.appointment_time < a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes)\nHAVING (EXTRACT(EPOCH FROM (LEAST(a.appointment_time + (INTERVAL '1 minute' * a.duration_minutes),\n b.appointment_time + (INTERVAL '1 minute' * b.duration_minutes))\n - GREATEST(a.appointment_time, b.appointment_time))) / 60) >= 15;", "sql": null }, { "role": "user", "content": "For each patient, find the next appointment after each one. Return patient_id, appointment_id, next_appointment_id, and the waiting time in minutes between them.", "sql": null }, { "role": "assistant", "content": "SELECT A.patient_id,\n A.appointment_id AS current_id,\n B.appointment_id AS next_id,\n EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 AS wait_minutes\nFROM healthcare.appointments A\nJOIN healthcare.appointments B\n ON A.patient_id = B.patient_id\n AND B.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = A.patient_id\n AND appointment_time > A.appointment_time\n );", "sql": null }, { "role": "user", "content": "Now include only the pairs where the waiting time is less than 30 minutes.", "sql": null }, { "role": "assistant", "content": "SELECT A.patient_id,\n A.appointment_id AS current_id,\n B.appointment_id AS next_id,\n EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 AS wait_minutes\nFROM healthcare.appointments A\nJOIN healthcare.appointments B\n ON A.patient_id = B.patient_id\n AND B.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = A.patient_id\n AND appointment_time > A.appointment_time\n )\nWHERE EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 < 30;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )
[ { "role": "user", "content": "Find all pairs of law firms founded in the same year, showing both firm names and the shared founding year.", "sql": null }, { "role": "assistant", "content": "SELECT f1.firm_name AS firm1, f2.firm_name AS firm2, EXTRACT(YEAR FROM f1.founded_date) AS founding_year\nFROM legal_services.law_firms f1\nJOIN legal_services.law_firms f2\n ON EXTRACT(YEAR FROM f1.founded_date) = EXTRACT(YEAR FROM f2.founded_date)\n AND f1.firm_id < f2.firm_id;", "sql": null }, { "role": "user", "content": "Retrieve each managing partner who oversees more than one firm, showing the managing_partner_id and the count of firms they manage.", "sql": null }, { "role": "assistant", "content": "SELECT managing_partner_id, COUNT(*) AS firm_count\nFROM legal_services.law_firms\nGROUP BY managing_partner_id\nHAVING COUNT(*) > 1;", "sql": null }, { "role": "user", "content": "Actually, I want to include the names of the firms under each managing partner, separated by commas.", "sql": null }, { "role": "assistant", "content": "SELECT managing_partner_id,\n COUNT(*) AS firm_count,\n STRING_AGG(firm_name, ', ') AS firms\nFROM legal_services.law_firms\nGROUP BY managing_partner_id\nHAVING COUNT(*) > 1;", "sql": null }, { "role": "user", "content": "Also, exclude any records where the managing_partner_id is null and sort the results by firm_count descending.", "sql": null }, { "role": "assistant", "content": "SELECT managing_partner_id,\n COUNT(*) AS firm_count,\n STRING_AGG(firm_name, ', ') AS firms\nFROM legal_services.law_firms\nWHERE managing_partner_id IS NOT NULL\nGROUP BY managing_partner_id\nHAVING COUNT(*) > 1\nORDER BY firm_count DESC;", "sql": null }, { "role": "user", "content": "Show me the names and phone numbers of all law firms founded in the same city.", "sql": null }, { "role": "assistant", "content": "SELECT lf1.firm_name AS firm1_name, lf1.phone AS firm1_phone, lf2.firm_name AS firm2_name, lf2.phone AS firm2_phone, lf1.address \nFROM legal_services.law_firms lf1\nJOIN legal_services.law_firms lf2 ON lf1.address = lf2.address AND lf1.firm_id < lf2.firm_id;", "sql": null }, { "role": "user", "content": "List all law firms that do not have a managing partner listed.", "sql": null }, { "role": "assistant", "content": "SELECT firm_name, phone, address, founded_date\nFROM legal_services.law_firms\nWHERE managing_partner_id IS NULL;", "sql": null }, { "role": "user", "content": "List all law firms that do not have a website registered, including their firm name and phone.", "sql": null }, { "role": "assistant", "content": "SELECT firm_name, phone\nFROM legal_services.law_firms\nWHERE website IS NULL OR website = '';", "sql": null }, { "role": "user", "content": "Show me law firms that were founded after 2018 and have a website provided.", "sql": null }, { "role": "assistant", "content": "SELECT firm_name, founded_date, website\nFROM legal_services.law_firms\nWHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '';", "sql": null }, { "role": "user", "content": "Actually, only include firms where the phone number starts with '+1'.", "sql": null }, { "role": "assistant", "content": "SELECT firm_name, founded_date, website, phone\nFROM legal_services.law_firms\nWHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '' AND phone LIKE '+1%';", "sql": null }, { "role": "user", "content": "Also add the firm address and sort the results by founded_date descending.", "sql": null }, { "role": "assistant", "content": "SELECT firm_name, founded_date, website, phone, address\nFROM legal_services.law_firms\nWHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '' AND phone LIKE '+1%'\nORDER BY founded_date DESC;", "sql": null } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean ) CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) ) CREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id) hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id) PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post ) CREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )
[ { "role": "user", "content": "List the usernames and email addresses of users who have published posts with media_type 'video', along with the creation time of each post.", "sql": null }, { "role": "assistant", "content": "SELECT u.username, u.email, p.created_at\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nWHERE p.media_type = 'video';", "sql": null }, { "role": "user", "content": "Actually, I'd like to see how many hashtags each of those posts has. Include a column hashtag_count.", "sql": null }, { "role": "assistant", "content": "SELECT u.username, u.email, p.created_at, COUNT(ph.post_hashtag_id) AS hashtag_count\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nLEFT JOIN social_media.post_hashtags ph ON p.post_id = ph.post_id\nWHERE p.media_type = 'video'\nGROUP BY u.username, u.email, p.created_at;", "sql": null }, { "role": "user", "content": "Show a list of group chat names with their conversation_id, the total number of participants, and the total number of messages sent in each group chat.", "sql": null }, { "role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(cp.participant_id) AS participant_count,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nLEFT JOIN social_media.messages m ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY c.conversation_id, c.group_name;", "sql": null }, { "role": "user", "content": "Please filter to include only group chats that have at least 5 participants.", "sql": null }, { "role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(cp.participant_id) AS participant_count,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nLEFT JOIN social_media.messages m ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY c.conversation_id, c.group_name\nHAVING COUNT(cp.participant_id) >= 5;", "sql": null }, { "role": "user", "content": "Now order the results by message_count descending and limit to the top 10 group chats.", "sql": null }, { "role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(cp.participant_id) AS participant_count,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nLEFT JOIN social_media.messages m ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY c.conversation_id, c.group_name\nHAVING COUNT(cp.participant_id) >= 5\nORDER BY message_count DESC\nLIMIT 10;", "sql": null }, { "role": "user", "content": "I want to see each user's username and the number of posts they've made that include a media attachment of type 'image'.", "sql": null }, { "role": "assistant", "content": "SELECT u.username, COUNT(*) AS image_post_count\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nWHERE p.media_url IS NOT NULL\n AND p.media_type = 'image'\nGROUP BY u.username;", "sql": null }, { "role": "user", "content": "Only include users with more than 2 image posts.", "sql": null }, { "role": "assistant", "content": "SELECT u.username, COUNT(*) AS image_post_count\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nWHERE p.media_url IS NOT NULL\n AND p.media_type = 'image'\nGROUP BY u.username\nHAVING COUNT(*) > 2;", "sql": null }, { "role": "user", "content": "Retrieve the usernames and email addresses of users who updated their profiles in the last 30 days.", "sql": null }, { "role": "assistant", "content": "SELECT username, email\nFROM social_media.users\nWHERE updated_at >= NOW() - INTERVAL '30 days';", "sql": null }, { "role": "user", "content": "List all posts along with the user emails of the authors.", "sql": null }, { "role": "assistant", "content": "SELECT p.post_id, p.content, u.email\nFROM social_media.posts p\nJOIN social_media.users u ON p.user_id = u.user_id;", "sql": null }, { "role": "user", "content": "Show me all users and the posts they have created, including the user's username and the post content.", "sql": null }, { "role": "assistant", "content": "SELECT u.username, p.post_id, p.content\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id;", "sql": null }, { "role": "user", "content": "Actually, can you please also include the post creation time and only show posts that have a media attachment?", "sql": null }, { "role": "assistant", "content": "SELECT u.username, p.post_id, p.content, p.created_at\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nWHERE p.media_url IS NOT NULL AND p.media_url <> '';", "sql": null } ]
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
2