简体   繁体   English

MySQL | 计数行 IF 0 然后返回

[英]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.我想创建一个 function 来检查距离航路点一定距离内是否有任何位置。 the function to calculate the distance is already working.计算距离的 function 已经开始工作了。 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.在 MySQL 中创建此 function 并仅从 javascript 文件中调用它。
  2. Create this function within my js file and only read the mySQL table when the javascript function is called.在我的 js 文件中创建此 function 并仅在调用 javascript ZC1C425268E68385D1AB450 时读取 mySQL 表。

TIA TIA

ABBOV ABBOV

Syntax error is all.语法错误就是一切。 You need a closing parenthesis after loc_idloc_id之后需要一个右括号

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

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

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