douqiao6015 2011-11-11 13:41
浏览 15
已采纳

如何从表中检索数据?

I am working in PHP. This is my query:

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

This place table has three fields: placeId, PlaceName and Address. Now I want to calculate rating of placeId which are the result of above query. To calculate the rating I have another table rating in which there are two fields: placeId and noOfPerson.

Rating will be calculated by (noOfPerson/maximum_no_of_person) for each placeId. How can i implement this?

  • 写回答

1条回答 默认 最新

  • dongwei1921 2011-11-11 13:51
    关注

    Your query could do majority of work here, this will select values from place table joined with number of person for each place, ordered by ranking you need, top-bottom:

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数