简体   繁体   中英

MySQL | Count rows IF 0 then return

I want to create a function which check if there a any locations within a certain distance from a waypoint. the function to calculate the distance is already working. I start with the query shown below.

select loc_id from wp where calc_distance(52.15819, 6.40726, wp.lat, wp.lon) <100;

This query wil result in several rows, the next step would be to count the amount of rows, why won't the query below result in a number?

select count(loc_id from wp where calc_distance(52.15819, 6.40726, wp.lat, wp.lon) <100);

Any thoughts?

Small side question: What wuold be perferred:

  1. Ccreate this function within MySQL and only call it from within a javascript file.
  2. Create this function within my js file and only read the mySQL table when the javascript function is called.

TIA

ABBOV

Syntax error is all. You need a closing parenthesis after loc_id

select count(loc_id) from wp where calc_distance(52.15819, 6.40726, wp.lat, wp.lon) <100;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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