大家帮忙看下这个sql group by 字句报错“aa:标识符无效”应该怎么写select t.carno,
sum(decode(t.year,'2010', t.TINSURANCEPRICE,null)) as "2010",
sum(decode(t.year,'2011', t.TINSURANCEPRICE,null)) as "2011" ,
decode(t.year,'2010', t.TINSURANCEPRICE,null) as "aa"
from base_car_oninsurance t
where t.year=2011 or t.year=2010
group by t.carno,t.driver,"aa"

解决方案 »

  1.   

    aa 是别名,只是能在嵌一层!
    或是如下操作:
    select t.carno,
    sum(decode(t.year,'2010', t.TINSURANCEPRICE,null)) as "2010",
    sum(decode(t.year,'2011', t.TINSURANCEPRICE,null)) as "2011" ,
    decode(t.year,'2010', t.TINSURANCEPRICE,null) as "aa"
    from base_car_oninsurance t
    where t.year=2011 or t.year=2010
    group by t.carno,t.driver,decode(t.year,'2010', t.TINSURANCEPRICE,null)
      

  2.   

    group by 不能使用别名的,
    修改为 group by group by t.carno,t.driver, decode(t.year,'2010', t.TINSURANCEPRICE,null)
      

  3.   

    group by不能用别名
    order by可以用别名