diff --git a/data/questions_gen_postgres.csv b/data/questions_gen_postgres.csv index 793503b..3a3ec4d 100644 --- a/data/questions_gen_postgres.csv +++ b/data/questions_gen_postgres.csv @@ -220,8 +220,18 @@ Assume the rating of a business to be its average rating, and compute it before "Lowest daily closest price for symbol `VTI` in the past 7 days","SELECT MIN(sdp.sbDpClose) AS lowest_price FROM sbDailyPrice AS sdp JOIN sbTicker AS st ON sdp.sbDpTickerId = st.sbTickerId WHERE st.sbTickerSymbol = 'VTI' AND sdp.sbDpDate >= CURRENT_DATE - INTERVAL '7 days';",broker,date_functions, "Return the customer id and the difference between their time from joining to their first transaction. Ignore customers who haven't made any transactions.","SELECT c.sbCustId, MIN(t.sbTxDateTime) - c.sbCustJoinDate AS DaysFromJoinToFirstTransaction FROM sbCustomer c JOIN sbTransaction t ON c.sbCustId = t.sbTxCustId GROUP BY c.sbCustId",broker,date_functions, "number of transactions by users who joined in the past 70 days","SELECT COUNT(t.sbTxCustId) AS transaction_count FROM sbTransaction t JOIN sbCustomer c ON t.sbTxCustId = c.sbCustId WHERE c.sbCustJoinDate >= CURRENT_DATE - INTERVAL '70' DAY;",broker,date_functions, +"Return the treatment id, treatment start date, adverse event date and description of all adverse events that occured within 10 days after starting treatment","SELECT t.treatment_id, t.start_dt, ae.reported_dt, ae.description FROM adverse_events ae JOIN treatments t ON ae.treatment_id = t.treatment_id WHERE ae.reported_dt BETWEEN t.start_dt AND t.start_dt + INTERVAL '10 days';",derm_treatment,date_functions, +"List the last name, year of registration, and first treatment (date and id) by doctors who were registered 2 years ago.","WITH doc_first_treatment AS (SELECT d.doc_id, d.last_name, d.year_reg, t.treatment_id, t.start_dt, ROW_NUMBER() OVER (PARTITION BY d.doc_id ORDER BY t.start_dt ASC) AS rn FROM doctors d JOIN treatments t ON d.doc_id = t.doc_id WHERE d.year_reg = EXTRACT(YEAR FROM CURRENT_DATE) - 2 ) SELECT last_name, year_reg, start_dt AS first_treatment_date, treatment_id AS first_treatment_id FROM doc_first_treatment WHERE rn = 1;",derm_treatment,date_functions, +"what is average age of all registered male patients with private insurance currently?","SELECT AVG(EXTRACT(YEAR FROM AGE(CURRENT_DATE, date_of_birth))) AS avg_age FROM patients WHERE gender = 'Male' AND ins_type = 'private';",derm_treatment,date_functions, +"show all placebo treatment id, start and end date, where there concomitant_meds were started within 2 weeks of starting the treatment. also return the start and end dates of all concomitant drug usage.","SELECT t.treatment_id, t.start_dt AS treatment_start_date, t.end_dt AS treatment_end_date, cm.start_dt AS concomitant_med_start_date, cm.end_dt AS concomitant_med_end_date FROM treatments t JOIN concomitant_meds cm ON t.treatment_id = cm.treatment_id WHERE t.is_placebo = TRUE AND TO_DATE(cm.start_dt, 'YYYY-MM-DD') BETWEEN t.start_dt AND t.start_dt + INTERVAL '2 WEEK' ORDER BY t.treatment_id;",derm_treatment,date_functions, +"How many treatments for diagnoses containing 'psoriasis' (match with wildcards case-insensitively) involve drugs still under FDA trial and have not yet ended?","SELECT COUNT(*) FROM treatments t JOIN diagnoses d ON t.diag_id = d.diag_id JOIN drugs dr ON t.drug_id = dr.drug_id WHERE d.diag_name ILIKE '%psoriasis%' AND dr.fda_appr_dt IS NULL AND t.end_dt IS NULL;",derm_treatment,date_functions, +"What was the average transaction daily and monthly limit for the earliest setting snapshot in 2023?","SELECT AVG(tx_limit_daily) AS avg_daily_limit, AVG(tx_limit_monthly) AS avg_monthly_limit FROM consumer_div.user_setting_snapshot WHERE snapshot_date = (SELECT MIN(snapshot_date) FROM consumer_div.user_setting_snapshot WHERE snapshot_date >= '2023-01-01' AND snapshot_date < '2024-01-01' );",ewallet,date_functions, +"Which users did not get a notification within the first year of signing up? Return their usernames, emails and signup dates.","SELECT u.username, u.email, u.created_at FROM consumer_div.users u LEFT JOIN consumer_div.notifications n ON u.uid = n.user_id AND n.created_at BETWEEN u.created_at AND u.created_at + INTERVAL '1 year' WHERE n.user_id IS NULL;",ewallet,date_functions, +"what was the average user session duration in seconds split by device_type?","SELECT device_type, AVG(EXTRACT(EPOCH FROM (session_end_ts - session_start_ts))) AS avg_session_duration_seconds FROM consumer_div.user_sessions WHERE session_end_ts IS NOT NULL GROUP BY device_type;",ewallet,date_functions, +"Give me today's median merchant wallet balance for all active merchants whose category contains 'retail'","WITH retail_merchants AS (SELECT mid FROM consumer_div.merchants WHERE category ILIKE '%retail%' AND status = 'active' ), merchant_balances AS (SELECT balance FROM consumer_div.wallet_merchant_balance_daily wmbd JOIN retail_merchants rm ON wmbd.merchant_id = rm.mid WHERE DATE(wmbd.updated_at) = CURRENT_DATE ) SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY balance) AS median_balance FROM merchant_balances;",ewallet,date_functions, +"Which merchants earliest coupon start date was within a year of the merchant's registration? Return the merchant id, registration date, and earliest coupon id and start date","WITH earliest_coupons AS (SELECT c.merchant_id, MIN(c.start_date) AS earliest_coupon_start_date FROM consumer_div.coupons c GROUP BY c.merchant_id) SELECT m.mid AS merchant_id, m.created_at AS merchant_registration_date, ec.earliest_coupon_start_date, c.cid AS earliest_coupon_id FROM consumer_div.merchants m JOIN earliest_coupons ec ON m.mid = ec.merchant_id JOIN consumer_div.coupons c ON ec.merchant_id = c.merchant_id AND ec.earliest_coupon_start_date = c.start_date WHERE ec.earliest_coupon_start_date <= m.created_at + INTERVAL '1 year';",ewallet,date_functions, "Return the name and phone number of the salesperson with the shortest time from being hired to getting fired. Return the number of days he/she was employed for.","SELECT s.first_name, s.last_name, s.phone, s.termination_date - s.hire_date AS days_employed FROM salespersons s ORDER BY days_employed ASC LIMIT 1;",car_dealership,date_functions, "Return the number of payments made on weekends to the vendor named 'Utility Company'","SELECT COUNT(*) AS weekend_payments FROM payments_made WHERE vendor_name = 'Utility Company' AND EXTRACT(DOW FROM payment_date) IN (0, 6);",car_dealership,date_functions, "show me the daily total amount of payments received in the whole of last week, split by the payment_method","SELECT payment_date, payment_method, SUM(payment_amount) AS total_amount FROM payments_received WHERE payment_date BETWEEN DATE_TRUNC('WEEK', CURRENT_DATE) - INTERVAL '1 week' AND DATE_TRUNC('WEEK', CURRENT_DATE) GROUP BY payment_date, payment_method ORDER BY payment_date DESC, payment_method ASC;",car_dealership,date_functions, "Which cars were in inventory in the latest snapshot for march 2023? Return the car id, make, model, and year.","WITH latest_snapshot AS (SELECT MAX(snapshot_date) AS snapshot_date FROM inventory_snapshots WHERE snapshot_date BETWEEN '2023-03-01' AND '2023-03-31' ), latest_snapshot_data AS (SELECT inv.car_id FROM inventory_snapshots inv JOIN latest_snapshot ls ON inv.snapshot_date = ls.snapshot_date WHERE inv.is_in_inventory = TRUE ) SELECT c.id, c.make, c.model, c.year FROM cars c JOIN latest_snapshot_data lsd ON c.id = lsd.car_id;",car_dealership,date_functions, -"What were the total quarterly sales in 2023 grouped by customer's state? Represent each quarter as the first date in the quarter.","SELECT DATE_TRUNC('QUARTER', s.sale_date) AS QUARTER, c.state, SUM(s.sale_price) AS total_sales FROM sales s JOIN customers c ON s.customer_id = c.id WHERE EXTRACT(YEAR FROM s.sale_date) = 2023 GROUP BY c.state, QUARTER HAVING SUM(s.sale_price) > 0 ORDER BY QUARTER, c.state ;",car_dealership,date_functions, +"What were the total quarterly sales in 2023 grouped by customer's state? Represent each quarter as the first date in the quarter.","SELECT DATE_TRUNC('QUARTER', s.sale_date) AS QUARTER, c.state, SUM(s.sale_price) AS total_sales FROM sales s JOIN customers c ON s.customer_id = c.id WHERE EXTRACT(YEAR FROM s.sale_date) = 2023 GROUP BY c.state, QUARTER HAVING SUM(s.sale_price) > 0 ORDER BY QUARTER, c.state ;",car_dealership,date_functions, \ No newline at end of file