0
select  
logs.uid,
logs.event_value

from publicview.treasurehunters_ok logs
left join public.app_ok_cbaiodclebabababa_agg_users users  on logs.uid=users.uid
where  first_event_time>='01.09.2017 0:00:00'
and first_event_time <= '11.09.2017 0:00:00'
and logs.event ='balance_OK'

I need to sort each uid by time in ascending order and leave only the first values for logs.event_value

I.e

uid  logs.event_value
1      10
1      5
1      3

we need to return only 1 10 i.e. leave the first lines for each user. So it is possible to make?

psysky
  • 3,037
  • 5
  • 28
  • 64

1 Answers1

1

You need to pick one id only, the one with max date right? You can run partition by, something like this:

select * from (
select  
logs.uid,
logs.event_value,
ROW_NUMBER() OVER (PARTITION BY uid ORDER BY first_event_time DESC) r 

from publicview.treasurehunters_ok logs
left join public.app_ok_cbaiodclebabababa_agg_users users  on 
logs.uid=users.uid
where  first_event_time>='01.09.2017 0:00:00'
and first_event_time <= '11.09.2017 0:00:00'
and logs.event ='balance_OK') tab
where r=1
MiloBellano
  • 396
  • 1
  • 5
  • 15