#1248 - Every derived table must have its own alias? Error_mysql phpmyadmin

138 Views Asked by At
select (1- (s1 + s2 + s3) / (s4 + s5 + s6))*100,startdate
from (
  select sum(v1) as s1 ,sum(v2) as s2,sum(v3) as s3,sum(v4) as s4,sum(v5) as s5,sum(v6) as s6,startdate 
    from (
      select 
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfAal2TermsRej' then valeur else null end) as v1,
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfIpTermsRej' then valeur else null end) as v2,
        avg(case when indicateur like '%TdmTermGrp%' and compteur = 'pmNrOfTdmTermsRej' then valeur else null end) as v3,
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfAal2TermsReq' then valeur else null end) as v4,
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfIpTermsReq' then valeur else null end) as v5,
        avg(case when indicateur like '%TdmTermGrp%' and compteur = 'pmNrOfTdmTermsReq' then valeur else null end) as v6,
        startdate
      from MGW1 
      group by startdate
    )
    group by startdate
  )
2

There are 2 best solutions below

0
On

try this

select (1- (s1 + s2 + s3) / (s4 + s5 + s6))*100,startdate
from
(   select sum(v1) as s1 ,sum(v2) as s2,sum(v3) as s3,sum(v4) as s4,sum(v5) as s5,sum(v6) as s6,startdate 
    from
    (   select avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfAal2TermsRej' then valeur else null end) as v1,
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfIpTermsRej' then valeur else null end) as v2,
        avg(case when indicateur like '%TdmTermGrp%' and compteur = 'pmNrOfTdmTermsRej' then valeur else null end) as v3,
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfAal2TermsReq' then valeur else null end) as v4,
        avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfIpTermsReq' then valeur else null end) as v5,
        avg(case when indicateur like '%TdmTermGrp%' and compteur = 'pmNrOfTdmTermsReq' then valeur else null end) as v6,
        startdate
        from MGW1
        group by startdate
    ) xDerived1 --  NEED AN ALIAS HERE
    group by startdate
) xDerived2 --  NEED AN ALIAS HERE

Note the two derived table names I snuck in (xDerived1 and xDerived2). It gets past the Error Code 1248

0
On

i have syntaxe error in line 11:

select (1- (s1 + s2 + s3) / (s4 + s5 + s6))*100 as succ_rate,startdate as Time from ( select sum(v1) as s1 ,sum(v2) as s2,sum(v3) as s3,sum(v4) as s4,sum(v5) as s5,sum(v6) as s6,startdate from ( select avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfAal2TermsRej' then valeur else null end) as v1, avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfIpTermsRej' then valeur else null end) as v2, avg(case when indicateur like '%TdmTermGrp%' and compteur = 'pmNrOfTdmTermsRej' then valeur else null end) as v3, avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfAal2TermsReq' then valeur else null end) as v4, avg(case when indicateur like '%Vmgw%' and compteur = 'pmNrOfIpTermsReq' then valeur else null end) as v5, avg(case when indicateur like '%TdmTermGrp%' and compteur = 'pmNrOfTdmTermsReq' then valeur else null end) as v6, startdate from data where SUBSTR(date_format(startdate,'AAAA-%m-JJ HH:%m:%s'),1,10) like $P{date_debut} and MGW like $P{par_mgw} group by startdate, MGW)