php - Grouping and counting of records in Haversine Formula SQL Query -


i working on vehicle trading website. have table named vehicle around 20 fields including make, model etc of vehicle. writing search query retrieve cars in system group make along counts make.

so objective of vehicles in system grouped make along counts of make counts part not work correctly. returns total number of cars make ignoring distance calculation criteria.

i executing following following sql:

select * (select *,round(((acos(sin(51.4811109 * pi() / 180) * sin(latitude * pi() / 180) + cos(51.4811109 * pi() / 180) * cos(latitude * pi() / 180) * cos((-0.433641 - longitude) * pi() / 180)) * 180 / pi()) * 60 * 1.1515),2) distance, count(make) carcount `vehicle` `t` (status='active')) v group make having distance<=10   

it returning correct except carcount returns 325 bmw cars in system(total bmw cars in system) instead of 12 bmw cars(only 10 cars exist in 10 miles distance).

can see doing wrong? help.

you need have condition in clause not having

select *, count(*)  (select *,round(((acos(sin(51.4811109 * pi() / 180) *                sin(latitude * pi() / 180) + cos(51.4811109 *                pi() / 180) *               cos(latitude * pi() / 180) *                cos((-0.433641 - longitude) * pi() / 180)) *               180 / pi()) * 60 * 1.1515),2) distance `vehicle` `t`  (status='active')) v distance<=10  group make  

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -