MySQL排序号

举例:

SELECT  (@i:[email protected]+1) AS PM,A.*,

   U.TNAME, 

   U.ID_NUM, 

   U.ORG_NAME,

   CASE WHEN U.SEXFLAG=1 THEN '男' WHEN U.SEXFLAG=2 THEN '女' ELSE '' END SEX,

   CASE WHEN LENGTH(ID_NUM) = 18 THEN YEAR(NOW()) - CAST(SUBSTRING(ID_NUM, 7, 4) AS SIGNED) ELSE '' END AS AGE 

     FROM TB_GH_MARATHON A  

     LEFT JOIN TB_GH_USER U ON A.USER_ID = U.USER_ID 

     ,(SELECT @i:=0) t

     WHERE 1=1 AND A.STATE = '1'

加上红色字体的代码即可

猜你喜欢

转载自blog.51cto.com/hebinteng/2441759