我正在尝试分析首次购买后30天内购买的用户。我不断得到
错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在':: date)附近使用正确的语法-整数'30'AND i.customer_id = o.customer_id group by o.custome在第7行
这是我运行的代码。
select
o.customer_id,
o.purchase_time
from orders as o
join orders as i on
i.purchase_time <= o.purchase_time AND
i.purchase_time >= (o.purchase_time :: date) - integer '30' AND
i.customer_id = o.customer_id
group by o.customer_id, o.purchase_time;
答案 0 :(得分:0)
我怀疑这是您想要的MySQL语法:
select o.*
from orders o
where exists (select 1
from orders o2
where o2.customer_id = o.customer_id and
o2.purchase_time > o.purchase_time and
o2.purchase_time <= purchase_time + interval 30 day
);