【问题标题】:Using a LIKE SQL statement in Express/Node在 Express/Node 中使用 LIKE SQL 语句
【发布时间】:2016-11-27 09:40:31
【问题描述】:

我有一个我试图调用的 SQL 查询,它搜索与关键字匹配的单词,然后在半径范围内搜索结果

此查询可以使用,但只能使用“LIKE ?”进行搜索不是“喜欢 %?%

connection.query("SELECT *, ( 3959 * acos (cos ( radians(?) )* cos( radians( lat ) )* cos( radians( lng ) - radians(?) )+ sin ( radians(?) )* sin( radians( lat ) ))) AS distance FROM job_posting where job_title like ? HAVING distance < 25",
        [lat, lng, lat, keyword], function(error, result) {
        console.log(result)
    })  

但我需要在最后的关键字值周围加上 %%,就像这样

job_posting where job_title like %?% HAVING distance < 25"  

我根本无法让它运行带有 % 符号的查询。有关如何解决此问题的任何提示?

【问题讨论】:

  • 你不能把% 符号放在关键字之前 作为查询参数传入吗?
  • 是的,我可以。谢谢小伙子!!

标签: javascript mysql sql node.js express


【解决方案1】:
var keyword = ("%" + req.query.keyword + "%")

【讨论】:

    猜你喜欢
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    相关资源
    最近更新 更多