gpt-4o-2024-05-13· OpenAI
WildChat-4.8M (AI2)
SQL面试题。给了一个table, 里面是关于用户的信息,有userid, employer, transactiondate等。要求写出转化成direct…
- User
SQL面试题。给了一个table, 里面是关于用户的信息,有user_id, employer, transaction_date等。要求写出转化成direct deposit的用户以及他们的转化日期。direct deposit定义是:用户从同一个employer那里get paid, 30天内至少两个不同的日期,差不多的金额(within 25%)
- Assistant
这是一个非常有趣的SQL问题。要求找出用户从同一个雇主那里在30天内有两次交易日期且金额相差在25%以内的用户转化成direct deposit的日期。下面是一个可能的解决方案。
假设表名为
user_transactions,且schema如下:CREATE TABLE user_transactions ( user_id INT, employer VARCHAR(255), transaction_date DATE, amount DECIMAL(10, 2) );根据这个定义,下面是一个SQL查询:
WITH potential_direct_deposits AS ( SELECT t1.user_id, t1.employer, t1.transaction_date AS date1, t2.transaction_date AS date2, t1.amount AS amount1, t2.amount AS amount2 FROM user_transactions t1 INNER JOIN user_transactions t2 ON t1.user_id = t2.user_id AND t1.employer = t2.employer AND t1.transaction_date < t2.transaction_date AND t2.transaction_date <= DATE_ADD(t1.transaction_date, INTERVAL 30 DAY) AND ABS(t1.amount - t2.amount) / t1.amount <= 0.25 ) SELECT user_id, employer, MIN(date1) AS conversion_date FROM potential_direct_deposits GROUP BY user_id, employer;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.