默认情况下,MySQL将null算作最小值。
使用:
if(isnull(字段名),1,0)
说明:它的意思是将该字段根据是否为null值分成两部分,0相当于null值部分放在最后面,1相当于非null值部分放在前面,在排序的时候,先根据这一属性进行升序排列
select city_code, ins_code, organ_type, organ_name, organ_address, organ_access_url, state, longitude, latitude, area, organ_category, adCode, organ_catagery , ROUND( 6371.393 * 2 * ASIN( SQRT( POW( SIN( ( #{latitude,jdbcType=DOUBLE} * PI() / 180 - latitude * PI() / 180 ) / 2 ), 2 ) + COS(#{latitude,jdbcType=DOUBLE} * PI() / 180) * COS(latitude * PI() / 180) * POW( SIN( ( #{longitude,jdbcType=DOUBLE} * PI() / 180 - longitude * PI() / 180 ) / 2 ), 2 ) ) ) * 1000 * #{val} )/1000 AS dis FROM wh_institution where city_code = #{cityCode,jdbcType=VARCHAR} and ins_code = #{insCode,jdbcType=VARCHAR} and organ_type = #{organType,jdbcType=VARCHAR} and state = ‘1‘ ORDER BY if(isnull(dis),1,0), dis, CONVERT(organ_name USING gbk) COLLATE gbk_chinese_ci ASC LIMIT #{startRow},#{endRow}
原文地址:https://www.cnblogs.com/zyf-yxm/p/12155626.html
时间: 2024-10-08 15:25:37