finish?!
This commit is contained in:
@@ -90,10 +90,34 @@ select
|
|||||||
from
|
from
|
||||||
chat_messages cm
|
chat_messages cm
|
||||||
where
|
where
|
||||||
entity_id = 37529075
|
entity_id = 37548545
|
||||||
order by created_at
|
order by created_at
|
||||||
offset 1;
|
offset 1;
|
||||||
|
|
||||||
|
with tmp as
|
||||||
|
(select
|
||||||
|
created_by,
|
||||||
|
created_at,
|
||||||
|
created_by = lag(created_by) over(order by created_at) as test
|
||||||
|
from
|
||||||
|
chat_messages cm
|
||||||
|
where
|
||||||
|
entity_id = 37548545
|
||||||
|
order by created_at)
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from tmp
|
||||||
|
where tmp.test = false or tmp.test is null
|
||||||
|
|
||||||
|
|
||||||
|
select
|
||||||
|
entity_id,
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
created_by = lag(created_by) over(partition by entity_id order by created_at) as tmp
|
||||||
|
from
|
||||||
|
chat_messages cm
|
||||||
|
order by created_at
|
||||||
|
|
||||||
-- result
|
-- result
|
||||||
with tmp as
|
with tmp as
|
||||||
@@ -117,16 +141,66 @@ group by tmp.created_by
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
select
|
||||||
|
created_by,
|
||||||
|
extract(day from cast(to_timestamp(created_at) as date)) as time_casted,
|
||||||
|
avg(cast(to_timestamp(created_at) as time)) over() as test
|
||||||
|
from
|
||||||
|
chat_messages cm
|
||||||
|
|
||||||
|
|
||||||
|
select cast(to_timestamp(1729931470) as time)
|
||||||
|
|
||||||
|
select greatest(cast(to_timestamp(1729931470) as time),
|
||||||
|
'12:00:00') as test
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
with tmp_table2 as
|
||||||
|
(with tmp_table as
|
||||||
|
(select
|
||||||
|
*,
|
||||||
|
cast(to_timestamp(created_at) as time) as dtime,
|
||||||
|
coalesce(created_by <> lag(created_by) over(partition by entity_id order by created_at), true) as not_dupl,
|
||||||
|
row_number() over(partition by entity_id order by created_at) as num
|
||||||
|
from
|
||||||
|
chat_messages cm
|
||||||
|
order by entity_id, created_at)
|
||||||
|
select
|
||||||
|
*,
|
||||||
|
dtime,
|
||||||
|
case when (dtime < '09:30:00'::time and created_by <> 0)
|
||||||
|
then '24:00:00'::time - lag(dtime) over(partition by entity_id order by created_at)
|
||||||
|
when (dtime < '09:30:00'::time and created_by = 0)
|
||||||
|
then dtime -'09:30:00'::time
|
||||||
|
when (lag(dtime) over(partition by entity_id order by created_at) > dtime)
|
||||||
|
then greatest(dtime - lag(dtime) over(partition by entity_id order by created_at),
|
||||||
|
lag(dtime) over(partition by entity_id order by created_at) - dtime)
|
||||||
|
else dtime - lag(dtime) over(partition by entity_id order by created_at)
|
||||||
|
end as diff_time
|
||||||
|
from tmp_table
|
||||||
|
where tmp_table.not_dupl
|
||||||
|
and
|
||||||
|
not (tmp_table.num = 1 and tmp_table.created_by <> 0))
|
||||||
|
select
|
||||||
|
r.rop_name,
|
||||||
|
m.name_mop,
|
||||||
|
cast(to_timestamp(created_at) as timestamp) as datetime,
|
||||||
|
diff_time
|
||||||
|
from
|
||||||
|
tmp_table2 as tt2
|
||||||
|
join
|
||||||
|
managers as m on m.mop_id = tt2.created_by
|
||||||
|
join
|
||||||
|
rops as r on r.rop_id = m.rop_id::int4
|
||||||
|
where
|
||||||
|
created_by <> 0
|
||||||
|
|
||||||
|
select abs('09:35:00'::time - '09:36:00'::time)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user