在MySQL中查询某条数据的排名

//mysql可以执行,mybatis不能解析
SET @c=0;
  SELECT * FROM (
  SELECT nurse_id,nurse_header,nurse_mark,@c:=@c+1 AS ranks FROM nurse ORDER BY nurse_mark DESC
  ) nurse WHERE nurse_id = #{nurseId,jdbcType=CHAR} 


//mysql和mybatis可以执行
SELECT nurse_id,nurse_header,nurse_mark, @rownum := @rownum +1 AS ranks,nurse_createtime
  FROM nurse t, (SELECT@rownum :=0) r 
  WHERE nurse_id = #{nurseId,jdbcType=CHAR}
  ORDER BY nurse_mark DESC,nurse_createtime ASC 

2种方式都可以在MySQL中执行,但是放到xml文件中第一张方法就不能使用,因为@这个符号不能被解析

你可能感兴趣的:(数据库,HTML5,Java)