与这个问题非常相似:https://docs.aws.amazon.com/transfer/latest/userguide/sftp.ug.pdf#page=28&zoom=100,0,776,但对于MySQL(版本5.5.56-MariaDB,其中窗口函数为NA)
我需要2个额外的列标志,标识为:
输出应包含5列:
伪数据也可以在该问题中找到。
我的尝试
select br.email
, (select count(*)
from bookings r1
where r1.Email = br.Email
and r1.id < br.id
) as repeat_rank
, (select count(*)
from bookings r2
where r2.Email = br.Email
and r2.id < br.id
and r2.OutBoundRoute = br.OutBoundRoute
) as same_route_repeat_rank
, (select count(*)
from bookings r3
where r3.Email = br.Email
and r3.id < br.id
and r3.OutBoundRoute <> br.OutBoundRoute
) as new_route_repeat_rank
, *
from bookings br
where br.TransactionDate < current_date
此查询的问题是,如果先前的购买路线不同,则same_route_repeat_rank
会重置为0,但如果客户在过去的任何时间购买了相同的路线,我希望它带回数字> 0