ERROR 1111 (HY000): Invalid use of group function with max and sum function Mysql

45 views Asked by At

I try this query

 select a2.Email_account, o2.Numero_ordine, totale_ordine2.totale as totale_ordine, totale_ordine1.totale as totale_riferimento
from
    account a1, account a2, ordine o1, ordine o2,
    (
        select o.Numero_ordine as ordine,  SUM(b.Prezzo * b.Quantita) as totale
        from biglietto b, ordine o
        where
            b.Numero_ordine = o.Numero_ordine
        group by b.Numero_ordine
    ) totale_ordine1,
    (
        select o.Numero_ordine as ordine,  SUM(b.Prezzo * b.Quantita) as totale from biglietto b, ordine o
        where
            b.Numero_ordine = o.Numero_ordine
        group by b.Numero_ordine
    ) totale_ordine2
where 
    a1.Email_account ='[email protected]'
    and a1.Email_account = o1.Email_account
    and o2.Email_account = a2.Email_account
    and o1.Numero_ordine = totale_ordine1.ordine
    and o2.Numero_ordine = totale_ordine2.ordine
    and totale_ordine2.totale > max(totale_ordine1.totale);

but i have the error ERROR 1111 (HY000): Invalid use of group function. I understand the problem is the sum and max function but i don't know how to resolve

0

There are 0 answers