ORA-00936:按案例顺序丢失表达式

时间:2014-10-18 23:59:11

标签: sql oracle case

您好我在此代码中缺少表达式有问题:

create or replace view tabulkaliga as 
  select t.nazov, zs.zapasov, zs.vyhier*nvl(tr.bodyvyhra,0)+zs.remiz*nvl(tr.bodyremiza,0) body, zs.vyhier,zs.remiz,zs.prehier,sl.dali,sl.dostali from
      tim t join 
      ligatim lt on t.id=lt.tim join 
      liga l on lt.liga=l.id join 
      sport s on l.sport=s.id join 
      trvanie tr on s.trvanie=tr.id inner join 
      zapasstat zs on zs.liga=l.id and t.id=zs.tim inner join 
      skoreliga sl on sl.liga=l.id and sl.tim=t.id 
        order by 
          case 
            when tr.bodyvyhra is null then (zs.vyhier+0.5*zs.remiz)/ZS.ZAPASOV desc,ZS.VYHIER desc
            else body desc, zs.vyhier desc, sl.dali desc
          end; 

请帮忙,谢谢

2 个答案:

答案 0 :(得分:0)

desc中不允许asccase个关键字。另外,一次只允许一列。你可以试试这个:

order by (case when tr.bodyvyhra is null then (zs.vyhier+0.5*zs.remiz)/ZS.ZAPASOV else body end) desc,
         ZS.VYHIER desc,
         sl.dali desc

请注意,这假设body是数字类型。

答案 1 :(得分:0)

替换

order by 
      case 
        when tr.bodyvyhra is null then (zs.vyhier+0.5*zs.remiz)/ZS.ZAPASOV desc,ZS.VYHIER desc
        else body desc, zs.vyhier desc, sl.dali desc
      end;

order by 
      case when tr.bodyvyhra is null then (zs.vyhier+0.5*zs.remiz)/ZS.ZAPASOV end desc,
      case when tr.bodyvyhra is not null then body end desc,
      ZS.VYHIER end desc,
      case when tr.bodyvyhra is not null then sl.dali end desc;

我在几种情况下拆分您的订单,因为:
1)案例只能包含表达式(或条件)
2)表达式必须在一个“类型组”中