Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Somma delle colonne di una tabella piot

    Buongiorno,
    ho il seguente problema: ho la seguente tabella pivot:
    tabella.jpg
    Devo aggiungere una riga con i totali dati dalla somma di ogni colonna.
    La tabella in questione è stata ottenuta tramite il codice seguente:

    codice:
    select detailDestinationName as 'Nome Coda', count(*) as 'Totale Chiamate ricevute',
    count(case when status = 'SERVED' then uniqueId else null end) as 'Chiamate Servite',
    (count(case when status = 'SERVED' then uniqueId else null end)/count(*)*100) as '% chiamate servite',
    ifnull((count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)/(count(*)-count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end))*100),0) as "Totale Abbandoni",
    count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end) as 'Chiamate non Servite Superiori a 30 secondi',
    ifnull((count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)/count(case when status = 'NOTSERVED' then uniqueId else null end )*100),0) as '% chiamate non servite superiore a 30 secondi', 
    count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end) as 'Chiamate non Servite Inferiori a 30 secondi', 
    ifnull((count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end)/count(case when status = 'NOTSERVED' then uniqueId else null end )*100),0) as '% chiamate non servite inferiore a 30 secondi'
    from chiamate_report_new
    
    group by detailDestinationId;


    Avete idea di come si possa fare?
    Grazie

  2. #2
    di che db si parla? cfr pt 4 del regolamento, pls

  3. #3
    MySql

  4. #4
    io farei una seconda query senza la group by finale; ma non conosco così bene MySql

  5. #5
    Quindi tu dici di fare una seconda query e mettere in union le due?

  6. #6
    o due query distinte o due query in union. ma, ripeto, magari esistono escamotage diversi in mysql

  7. #7
    Ho provato a realizzare la seguente query:

    codice:
    select detailDestinationName as 'Nome Coda', count(*) as 'Totale Chiamate ricevute',
    count(case when status = 'SERVED' then uniqueId else null end) as 'Chiamate Servite',
    (count(case when status = 'SERVED' then uniqueId else null end)/count(*)*100) as '% chiamate servite',
    ifnull((count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)/(count(*)-count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end))*100),0) as "Totale Abbandoni",
    count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end) as 'Chiamate non Servite Superiori a 30 secondi',
    ifnull((count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)/count(case when status = 'NOTSERVED' then uniqueId else null end )*100),0) as '% chiamate non servite superiore a 30 secondi', 
    count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end) as 'Chiamate non Servite Inferiori a 30 secondi', 
    ifnull((count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end)/count(case when status = 'NOTSERVED' then uniqueId else null end )*100),0) as '% chiamate non servite inferiore a 30 secondi'
    from chiamate_report_new
    group by detailDestinationId
    UNION
     select 'TOTALE' as 'Nome Coda',
      sum(count(*)) as 'Totale Chiamate ricevute',
      sum(count(case when status = 'SERVED' then uniqueId else null end)) as 'Chiamate Servite',
      sum((count(case when status = 'SERVED' then uniqueId else null end)/count(*)*100)) as '% chiamate servite',
      sum(ifnull((count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)/(count(*)-count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end))*100),0)) as "Totale Abbandoni",
      sum(count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)) as 'Chiamate non Servite Superiori a 30 secondi',
      sum(ifnull((count(case when status = 'NOTSERVED' and waitingTime >= 30 then uniqueId else null end)/count(case when status = 'NOTSERVED' then uniqueId else null end )*100),0)) as '% chiamate non servite superiore a 30 secondi', 
      sum(count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end)) as 'Chiamate non Servite Inferiori a 30 secondi',
      sum(ifnull((count(case when status = 'NOTSERVED' and waitingTime < 30 then uniqueId else null end)/count(case when status = 'NOTSERVED' then uniqueId else null end )*100),0)) as '% chiamate non servite inferiore a 30 secondi'
      from chiamate_report_new;
    ma ottengo l'errore:Error Code: 1111. Invalid use of group function

    Cosa ho sbagliato?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.