create table user_logs (
  user_id int
);

insert into user_logs select floor(rand()*100) from seq_1_to_10000;


analyze format=json
with log_users_with_their_purchases as (
select 
  user_id,  
  (select amount 
   from sales 
   where user_id=OUTR.user_id
   ORDER BY sales_date limit 1
  ) as LAST_SALE_AMT
from 
  user_logs as OUTR
)
select count(*)
from log_users_with_their_purchases  
where 
  LAST_SALE_AMT < 0.5;


