在select语句外操作变量

mccptt67  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(231)
SELECT @rownum := @rownum +1 AS rank, 
    round(LAT_N,4) as lat 
FROM STATION 
HAVING rank = CEIL(@rowCount/2) 
ORDER BY LAT_N

我怎么能不显示军衔呢?或者如何在select之外操纵/分配变量?

xzv2uavs

xzv2uavs1#

使用子查询:

SELECT lat
FROM (SELECT @rownum := @rownum +1 AS rank, 
            round(LAT_N,4) as lat 
      FROM STATION CROSS JOIN
           (SELECT @rownum := 0) params
      ORDER BY lat_n
     ) s
WHERE rank = CEIL(@rowCount / 2) ;

请注意,在较新版本的mysql中,可能需要在子查询中进行排序。

相关问题