I need to choose top 3 most recnet orders for each individual using order_date.
i have been able to choose top 2 most recent using order_date. But then it becomes complicated down to top 3.
Please use only joins. i'm not familiar with more complicated methods.
Here is my code:
select individual_id, drop_date, response ,
cast(null as int(1)) as score
from #ACTIVITY_1
where drop_date = (select max(drop_date) from #ACTIVITY_1 as f where f.individual_id = #ACTIVITY_1.ind ividual_id)
or drop_date = (select max(drop_date) from #ACTIVITY_1 as f where f.individual_id = #ACTIVITY_1.ind ividual_id
and drop_date < (select max(drop_date) from #ACTIVITY_1 as f2 where f2.individual_i d = #ACTIVITY_1.ind ividual_id) )
Thanks for your help!
i have been able to choose top 2 most recent using order_date. But then it becomes complicated down to top 3.
Please use only joins. i'm not familiar with more complicated methods.
Here is my code:
select individual_id, drop_date, response ,
cast(null as int(1)) as score
from #ACTIVITY_1
where drop_date = (select max(drop_date) from #ACTIVITY_1 as f where f.individual_id = #ACTIVITY_1.ind ividual_id)
or drop_date = (select max(drop_date) from #ACTIVITY_1 as f where f.individual_id = #ACTIVITY_1.ind ividual_id
and drop_date < (select max(drop_date) from #ACTIVITY_1 as f2 where f2.individual_i d = #ACTIVITY_1.ind ividual_id) )
Thanks for your help!
Comment