table_1
包含以下列:user_id, order_id, transaction_time
transaction_time
的数据类型是timestamp
SELECT user_id
FROM table_1
WHERE transaction_time > date_sub(transaction_time, interval 20 MINUTE_SECOND)
我想让连续完成交易的人不到20分钟,但我缺乏这方面的知识。
试试这个,
SELECT user_id,
case when sum(case when transaction_time between transaction_time and dateadd(minute,20,transaction_time) then 1 else 0 end ) > 1
then 'User did transaction consecutively'
else 'No consecutive Transaction' end
FROM table_1
group by user_id
这将选择交易时间和交易时间后20分钟的窗口,并计算该用户在该窗口中的交易数量,然后返回计数大于1的位置
select
user_Id,
transaction_time,
date_add(transaction_time, interval 20 MINUTE_SECOND)
count(*) countofTransactions
from table_1
group by
user_Id,
transaction_time,
date_add(transaction_time, interval 20 MINUTE_SECOND)
having count(*)>1 --having more than one transaction in the window