Advertisement
fmartns

Untitled

Jan 15th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.77 KB | None | 0 0
  1. DROP TEMPORARY TABLE if EXISTS tmp_horarios_produto;
  2. CREATE TEMPORARY TABLE tmp_horarios_produto
  3. SELECT
  4. t.codigo,
  5. t.celulaId,
  6. t.dia,
  7. t.hora,
  8. SUM(t.qtdApontada) AS qtdApontada,
  9. SUM(t.tempoApontado) AS tempoApontado
  10. FROM (
  11. SELECT z.*,
  12. SUM(i.tempo),
  13. SUM(i.t1+i.t2+i.t3+i.t4+i.t5+i.t6+i.t7+i.t8+i.t9+i.t10+i.t11+i.t12),
  14. ROUND(SUM(i.tempo) / SUM(i.t1+i.t2+i.t3+i.t4+i.t5+i.t6+i.t7+i.t8+i.t9+i.t10+i.t11+i.t12),2) AS tempoUn,
  15. z.qtdApontada * ROUND(SUM(i.tempo) / SUM(i.t1+i.t2+i.t3+i.t4+i.t5+i.t6+i.t7+i.t8+i.t9+i.t10+i.t11+i.t12),2) AS tempoApontado
  16. FROM (
  17. SELECT
  18. c.id AS comandoId,
  19. c.codigo,
  20. a.celula_id AS celulaId,
  21. a.dia,
  22. a.hora,
  23. SUM(a.quantidade) AS qtdApontada,
  24. a.comando
  25. FROM apontamento a
  26. INNER JOIN comandos c ON c.numero = a.comando
  27. WHERE c.codigo = '4323001' AND a.setor = '001' AND a.quantidade > 0 AND a.dia >= '00010120' and a.dia <= '20250115'
  28. GROUP BY a.celula_id, a.dia, a.hora ,a.comando
  29. ORDER BY a.celula_id,a.dia, a.hora, a.comando
  30. ) AS z
  31. INNER JOIN itens_comando i ON i.idcomando = z.comandoId AND i.setor = '001'
  32. GROUP BY z.celulaId, z.dia, z.hora,z.comando
  33. ) AS t
  34. GROUP BY t.celulaId, t.dia, t.hora;
  35.  
  36.  
  37. DROP TEMPORARY TABLE if EXISTS tmp_carga_intervalo;
  38. CREATE TEMPORARY TABLE tmp_carga_intervalo
  39. SELECT
  40. lc.celulasid AS celulaId,
  41. d.dia,
  42. it.fim AS hora,
  43. SUM(ic.cargaMinutos - it.cargaMinutosDesvio) AS carga,
  44. it.id AS intervaloId
  45. FROM diassemana d
  46. INNER JOIN semanas s ON d.id_semana = s.id
  47. inner join lote_celula lc ON s.celula_id = lc.id
  48. inner join grupos_op go ON go.Codigo = lc.setor AND go.tipoEficienciaPremio = 1
  49. INNER JOIN intervalo_trabalho it ON it.diaId = d.id
  50. INNER JOIN intervalo_trabalho_colaboradores ic ON ic.intervaloTrabalhoId = it.id
  51. INNER JOIN tmp_horarios_produto t ON t.hora = it.fim AND t.dia = d.dia AND t.celulaId = lc.celulasid
  52. INNER JOIN cfrt c ON c.id = ic.colaboradorId AND c.contaEficiencia <> 1
  53. GROUP BY lc.celulasid, d.dia,it.id;
  54.  
  55. DROP TEMPORARY TABLE if EXISTS tmp_horarios_produto_aux;
  56. CREATE TEMPORARY TABLE tmp_horarios_produto_aux
  57. SELECT
  58. t.codigo,
  59. t.celulaId,
  60. t.dia,
  61. t.hora,
  62. SUM(t.qtdApontada) AS qtdApontada,
  63. SUM(t.tempoApontado) AS tempoApontado
  64. FROM (
  65. SELECT z.*,
  66. SUM(i.tempo),
  67. SUM(i.t1+i.t2+i.t3+i.t4+i.t5+i.t6+i.t7+i.t8+i.t9+i.t10+i.t11+i.t12),
  68. ROUND(SUM(i.tempo) / SUM(i.t1+i.t2+i.t3+i.t4+i.t5+i.t6+i.t7+i.t8+i.t9+i.t10+i.t11+i.t12),2) AS tempoUn,
  69. z.qtdApontada * ROUND(SUM(i.tempo) / SUM(i.t1+i.t2+i.t3+i.t4+i.t5+i.t6+i.t7+i.t8+i.t9+i.t10+i.t11+i.t12),2) AS tempoApontado
  70. FROM (
  71. SELECT
  72. c.id AS comandoId,
  73. c.codigo,
  74. a.celula_id AS celulaId,
  75. a.dia,
  76. a.hora,
  77. SUM(a.quantidade) AS qtdApontada,
  78. a.comando
  79. FROM apontamento a
  80. INNER JOIN comandos c ON c.numero = a.comando
  81. INNER JOIN tmp_horarios_produto t ON t.hora = a.hora AND t.dia = a.dia AND t.celulaId = a.celula_id
  82. WHERE c.codigo <> '4323001' AND a.setor = '001' AND a.quantidade > 0 AND a.dia >= '00010120' and a.dia <= '20250115'
  83. GROUP BY a.celula_id, a.dia, a.hora ,a.comando
  84. ORDER BY a.celula_id,a.dia, a.hora, a.comando
  85. ) AS z
  86. INNER JOIN itens_comando i ON i.idcomando = z.comandoId AND i.setor = '001'
  87. GROUP BY z.celulaId, z.dia, z.hora,z.comando
  88. ) AS t
  89. GROUP BY t.celulaId, t.dia, t.hora;
  90.  
  91. SELECT
  92. t.celulaId,
  93. t.dia,
  94. t.hora,
  95. t.carga,
  96. sum(p.tempoApontado) tempoApondadoProduto,
  97. sum(IFNULL(a.tempoApontado,0)) AS tempoApontadoOutros,
  98. ROUND(((sum(p.tempoApontado) + sum(IFNULL(a.tempoApontado,0))) / t.carga) * 100,2) AS efiHorario,
  99. ROUND((sum(p.tempoApontado) / (sum(p.tempoApontado) + sum(IFNULL(a.tempoApontado,0))))*100,2) AS percentualRefEfi
  100. FROM tmp_carga_intervalo t
  101. INNER JOIN tmp_horarios_produto p ON p.celulaId = t.celulaId AND p.dia = t.dia AND t.hora = p.hora
  102. LEFT JOIN tmp_horarios_produto_aux a ON a.celulaId = t.celulaId AND t.dia = a.dia AND t.hora = a.hora
  103. GROUP BY t.celulaId, t.dia, t.hora
  104. ORDER BY t.dia, t.celulaId;
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement