select bdz_name,
       sum(y_get_sum) as y_get,
       case
         when sum(y_get_sum) > 0 then
          Round((sum(y_get_sum) - sum(y_put_sum)) / sum(y_get_sum) * 100, 2) as
          y_bph     --ORA-00905: 缺少关键字
         else
          0
       end
  from mxph_line_energy
 group by bdz_name, v_rank, dt_year, dt_month
having v_rank = 110 and dt_year = 2006 and dt_month = 1
 order by bdz_name;
请问如何给 Round((sum(y_get_sum) - sum(y_put_sum)) / sum(y_get_sum) * 100, 2) 加个别名呀

解决方案 »

  1.   

    select bdz_name,
           sum(y_get_sum) as y_get,
           case
             when sum(y_get_sum) > 0 then
              Round((sum(y_get_sum) - sum(y_put_sum)) / sum(y_get_sum) * 100, 2)     
             else
              0
           end as y_bph
      from mxph_line_energy
      where  v_rank = 110 and dt_year = 2006 and dt_month = 1
     group by bdz_name, v_rank, dt_year, dt_month
     order by bdz_name;这样可能效率高点;as放 end后,或者不要as,直接中间有个空格就行。