MSSQL& PHP:按列排序只有2位数?为什么?

时间:2017-05-11 18:33:56

标签: php sql-server

我在近搜索中有一个SQL语句,在ORDER BY中有一个列。

但是,例如,这只排序前两个数字:

按列1 DESC排序

数据(已排序):

  • 999 - 9920 -988 -977 -9729 -960 -950 -900 -890 -8912

这是我的SQL:

$sql_nearme = "SELECT  * FROM ( SELECT place.facebook_likes,place.place_logo, place.place_rank, place.percent_points, place.points, place.place_id, place.place_adress, place.place_description, place.place_photo, place.place_name,(6371 * acos(cos(radians(".$map['results'][0]['geometry']['location']['lat'].")) * cos(
              radians(place.place_lat)
                ) * cos(
                    radians(place.place_long) - radians(".$map['results'][0]['geometry']['location']['lng'].")
                ) + sin(
                    radians(".$map['results'][0]['geometry']['location']['lat'].")
                ) * sin(
                    radians(place.place_lat)
                )
            )
        ) AS distance
FROM place) A WHERE A.distance < 100 ORDER BY facebook_likes DESC OFFSET ".$blatt_start." ROWS FETCH NEXT ".$blatt_end." ROWS ONLY";

1 个答案:

答案 0 :(得分:0)

您可以使用以下where子句:

FROM place) A WHERE A.distance < 100 ORDER BY 
  try_convert(int,Right(convert(varchar(10),facebook_likes),2)) DESC OFFSET ".$blatt_start." ROWS FETCH NEXT ".$blatt_end." ROWS ONLY";