【问题标题】:How can i retrieve data from a table?如何从表中检索数据?
【发布时间】:2011-11-11 21:51:48
【问题描述】:

我正在使用 PHP。这是我的查询:

$sql = "SELECT * 
        from place as s 
        where checkDistance($lati1,$longi1,s.lat,s.lon)<$dist";

此地点表包含三个字段:placeIdPlaceNameAddress。现在我想计算 placeId 的评分,这是上述查询的结果。为了计算评分,我有另一个表 rating,其中有两个字段:placeIdnoOfPerson

评分将由每个 placeId 的 (noOfPerson/maximum_no_of_person) 计算。我该如何实现?

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    您的查询可以在这里完成大部分工作,这将从place 表中选择值,并与每个地方的人数相结合,按您需要的排名从上到下排序:

    SELECT s.placeid, s.PlaceName, s.Address, r.noOfPerson
    FROM place as s JOIN rating as r ON (s.placeid = r.placeid)
    WHERE checkDistance($lati1,$longi1,s.lat,s.lon)
    ORDER BY r.noOfPerson / ( SELECT MAX(noOfPerson) FROM rating ) DESC
    

    【讨论】:

      猜你喜欢
      • 2013-05-16
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多