sql语句case when会报case关键字的错误

select * from shrzl a inner join
(select max(shrdh) shrdh,max(id) id from sfglb group by fhrdh)b on a.shrdh=b.shrdh
case when b.shrdh is not null then a.no=-1 end

 select a.*,
case when b.shrdh is not null then -1 else a.no end ano from shrzl a inner join 
(select max(shrdh) shrdh,max(id) id from sfglb group by fhrdh)b on a.shrdh=b.shrdh 

select a.*,
(case when b.shrdh is not null then -1 else a.no end) as ano
from shrzl a inner join
(select max(shrdh) shrdh,max(id) id from sfglb group by fhrdh)b on a.shrdh=b.shrdh;

CASE 语法:
CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result ...] [ELSE result] END

CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END

在第一个方案的返回结果中,value=compare-value。
而第二个方案的返回结果是第一种情况的真实结果。如果没有匹配的结果值,则返回结果为ELSE后的结果,如果没有ELSE 部分,则返回值为 NULL。

参考自:MySQL控制流程函数 http://www.data.5helpyou.com/article327.html