Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT mtg.idTemaGestion, mtg.detTemaGestion,
- count(mtg.idTemaGestion) as total
- from mac_gestion mg
- inner join mac360_mac_gestion mmg on mg.idMacGestion = mmg.idMacGestion_FK
- inner join mac360 m on m.idMac360 = mmg.idMac360_FK
- inner join mac_tipogestion tg on tg.idTipoGestion = mg.idTipoGestion_FK
- inner join datos_nomina dn on dn.idDatosNomina = m.idDatosNominaRecibe_FK
- inner join site si on si.idSite = dn.idSite_FK
- inner join mac_temagestion mtg on mtg.idTemaGestion = mg.idTemaGestion_FK
- where mg.error = 'si'
- and si.idSIte in (2)
- and tg.idTipoGestion in (1)
- group by mtg.idTemaGestion
- order by total desc;
- create table Errores (
- Titulo varchar(100),
- Cantidad INT
- )
- insert into Errores (Titulo, Cantidad)
- VALUES ('Error A', 15),
- ('Error B', 85),
- ('Error C', 25),
- ('Error D', 64),
- ('Error E', 10)
- SELECT *,
- C.ACUMULADO/Total
- FROM (SELECT t.Titulo,
- t.Cantidad,
- @acum:= @acum+ t.Cantidad AS ACUMULADO,
- tot.Total
- FROM Errores t
- JOIN (SELECT @acum:= 0) r
- JOIN (SELECT SUM(Cantidad) as 'Total' FROM Errores) tot
- ORDER BY t.Cantidad desc
- ) C
- WHERE C.ACUMULADO/Total <= 0.8
- drop table Errores
- ╔═══╦═════════╦══════════╦═══════════╦═══════╦═══════════════════╗
- ║ # ║ Titulo ║ Cantidad ║ ACUMULADO ║ Total ║ C.ACUMULADO/Total ║
- ╠═══╬═════════╬══════════╬═══════════╬═══════╬═══════════════════╣
- ║ 1 ║ Error B ║ 85 ║ 85 ║ 199 ║ 0,42713567839196 ║
- ╠═══╬═════════╬══════════╬═══════════╬═══════╬═══════════════════╣
- ║ 2 ║ Error D ║ 64 ║ 149 ║ 199 ║ 0,748743718592965 ║
- ╚═══╩═════════╩══════════╩═══════════╩═══════╩═══════════════════╝
Add Comment
Please, Sign In to add comment