感谢您的帮助,我在PostgreSQL中有以下表格
这些列是
ON = END - START
IDLE = START (LINE 2) - END (LINE 1)
我需要使用select计算"idle“...空闲值是使用从行1的末尾减去行2的开始来获得的,按照示例,空闲值00:25是09:25 - 09:00。
我无法为此创建逻辑,也无法创建计算它的代码。
这是我的选择
select st.id,
st.tvd_unidade,
st.tvd_pdv,
st.tvd_cupom,
st.tvd_operador,
min(st.tvd_data_hora) as start_at,
max(en.tvd_data_hora) as end_at,
max(en.tvd_data_hora) - min(st.tvd_data_hora) as produtivo
from ger st
inner join ger en on st.tvd_unidade = en.tvd_unidade and st.tvd_pdv = en.tvd_pdv and st.tvd_cupom = en.tvd_cupom
where en.tvd_tipo_reg in ('FINN','FINn')
and st.tvd_tipo_reg in ('INFN','INFn')
group by 1
发布于 2019-05-30 09:08:15
在您担心数学之前,您需要能够在一行上看到所需的所有数据。要查看其他行的数据,可以使用窗口函数。在本例中,您可以使用滞后窗口函数来查看前一行,如下所示
Select start, end, lag(end) over (order by [your sort key]) as lastEnd
from table
order by [your sort key]
应该会给你你需要的数据。一旦你确定你已经得到了正确的数据,你就可以开始对on和idle进行数学计算
https://stackoverflow.com/questions/56370179
复制相似问题