简体   繁体   English

如何从表中检索数据?

[英]How can i retrieve data from a table?

I am working in PHP. 我在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 . 这个位置表有三个字段: placeIdPlaceNameAddress Now I want to calculate rating of placeId which are the result of above query. 现在我想计算placeId的评级,这是上述查询的结果。 To calculate the rating I have another table rating in which there are two fields: placeId and noOfPerson . 为了计算评级,我有另一个表评级 ,其中有两个字段: placeIdnoOfPerson

Rating will be calculated by (noOfPerson/maximum_no_of_person) for each placeId. 对于每个placeId,评级将由(noOfPerson / maximum_no_of_person)计算。 How can i implement this? 我该如何实现呢?

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: 您的查询可以在这里完成大部分工作,这将从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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM