Guest User

Untitled

a guest
Nov 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. SELECT mtg.idTemaGestion, mtg.detTemaGestion,
  2. count(mtg.idTemaGestion) as total
  3. from mac_gestion mg
  4. inner join mac360_mac_gestion mmg on mg.idMacGestion = mmg.idMacGestion_FK
  5. inner join mac360 m on m.idMac360 = mmg.idMac360_FK
  6. inner join mac_tipogestion tg on tg.idTipoGestion = mg.idTipoGestion_FK
  7. inner join datos_nomina dn on dn.idDatosNomina = m.idDatosNominaRecibe_FK
  8. inner join site si on si.idSite = dn.idSite_FK
  9. inner join mac_temagestion mtg on mtg.idTemaGestion = mg.idTemaGestion_FK
  10. where mg.error = 'si'
  11. and si.idSIte in (2)
  12. and tg.idTipoGestion in (1)
  13. group by mtg.idTemaGestion
  14. order by total desc;
  15.  
  16. create table Errores (
  17. Titulo varchar(100),
  18. Cantidad INT
  19. )
  20.  
  21. insert into Errores (Titulo, Cantidad)
  22. VALUES ('Error A', 15),
  23. ('Error B', 85),
  24. ('Error C', 25),
  25. ('Error D', 64),
  26. ('Error E', 10)
  27.  
  28. SELECT *,
  29. C.ACUMULADO/Total
  30. FROM (SELECT t.Titulo,
  31. t.Cantidad,
  32. @acum:= @acum+ t.Cantidad AS ACUMULADO,
  33. tot.Total
  34. FROM Errores t
  35. JOIN (SELECT @acum:= 0) r
  36. JOIN (SELECT SUM(Cantidad) as 'Total' FROM Errores) tot
  37. ORDER BY t.Cantidad desc
  38. ) C
  39. WHERE C.ACUMULADO/Total <= 0.8
  40.  
  41.  
  42. drop table Errores
  43.  
  44. ╔═══╦═════════╦══════════╦═══════════╦═══════╦═══════════════════╗
  45. ║ # ║ Titulo ║ Cantidad ║ ACUMULADO ║ Total ║ C.ACUMULADO/Total ║
  46. ╠═══╬═════════╬══════════╬═══════════╬═══════╬═══════════════════╣
  47. ║ 1 ║ Error B ║ 85 ║ 85 ║ 199 ║ 0,42713567839196 ║
  48. ╠═══╬═════════╬══════════╬═══════════╬═══════╬═══════════════════╣
  49. ║ 2 ║ Error D ║ 64 ║ 149 ║ 199 ║ 0,748743718592965 ║
  50. ╚═══╩═════════╩══════════╩═══════════╩═══════╩═══════════════════╝
Add Comment
Please, Sign In to add comment