LIKE更改结果的自变量顺序不同

时间:2019-03-06 16:24:33

标签: mysql mariadb

我在MySQL(MariaDB)中有一个非常奇怪的情况。我有一个查询:

  • 两个keywords
  • 一个location
  • 一个salary
  • 一个limit

如果keywords参数的排列顺序不同,则会得到不同的结果:

查询1:

bindings: [ '%Javascript%', '%Vue.js%', 'Krakow', '3000', 15 ],
sql:
   'select `jobs`.*,`companies`.`name`as `company_name`, 
            `companies`.`logo` as `company_logo`, `projects`.`staff`, 
            `projects`.`breakdown`, `projects`.`methodology`, 
            `projects`.`stack`, `projects`.`perks` 
    from `jobs` 
        inner join `companies` on `jobs`.`company_id` = `companies`.`id` 
        inner join `projects` on `jobs`.`project_id` = `projects`.`id` 
    where `keywords` like ? 
       or `keywords` like ? 
       and `location` = ? 
       and `salary_min` >= ? 
    order by `jobs`.`salary_min` desc 
    limit ?' }
count:  45

查询2:

bindings: [ '%Vue.js%', '%Javascript%', 'Krakow', '3000', 15 ],
sql:
   'select `jobs`.*, `companies`.`name`as `company_name`, 
            `companies`.`logo` as `company_logo`, `projects`.`staff`, 
            `projects`.`breakdown`, `projects`.`methodology`, 
            `projects`.`stack`, `projects`.`perks` 
    from `jobs` 
        inner join `companies` on `jobs`.`company_id` = `companies`.`id` 
        inner join `projects` on `jobs`.`project_id` = `projects`.`id` 
    where `keywords` like ? 
       or `keywords` like ? 
      and `location` = ? 
      and `salary_min` >= ? 
    order by `jobs`.`salary_min` desc 
    limit ?' }
count:  6

问题: -为什么它不只从选定的location返回作业? -为什么由于keywords的顺序有计数差异?

很想了解这一点-无法将我的头缠住它。我正在使用Knex执行这些查询。

1 个答案:

答案 0 :(得分:1)

import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np from matplotlib import animation W = 3 H = 1.2 mpl.rc('text', usetex=True) mpl.rc('font', family='serif') plt.style.use(['ggplot', 'dark_background']) def create_circle(x, y): circle = plt.Circle((x, y), radius=1, fill=False, edgecolor='skyblue', lw=2) return circle def stereo_project(p): x = p[0] y = p[1] # transformation x1 = x / (1 - y) y1 = 0 return x1, y1 def rotate(p, angle): vec = np.array([p[0], p[1]]).reshape(2, 1) theta = angle R = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]]) point = R.dot(vec) return point[0][0], point[1][0] def update_plot(angle, text, plot, plot1, plot2, plot3): p = (0, 1) R_x, R_y = rotate(p, angle) SR_x, SR_y = stereo_project((R_x, R_y)) x = [p[0], R_x] y = [p[1], R_y] x1 = [R_x, SR_x] y1 = [R_y, SR_y] plot.set_data(x, y) plot1.set_data(x1, y1) plot2.set_data([R_x], [R_y]) plot3.set_data([SR_x], [SR_y]) R_x, R_y = rotate(p, angle) text.set_text('$({0:.2f}, {1:.2f})$'.format(R_x, R_y)) text.set_position((R_x, R_y)) return text, plot, plot1 def create_animation(): fig = plt.figure() ax = plt.axes(xlim=(-W, W), ylim=(-H, H)) plot = plt.plot([], [], '-o', markersize=5, color='c')[0] plot1 = plt.plot([], [], '-o', markersize=5, color='c')[0] plot2 = plt.plot([], [], '-o', markersize=5, color='m')[0] plot3 = plt.plot([], [], '-o', markersize=5, color='lime')[0] ax.set_aspect('equal') circle = create_circle(0, 0) ax.add_patch(circle) l1 = [-3, 3] l2 = [0, 0] plt.plot(l1, l2) p = (0, 1) R_x, R_y = rotate(p, 0) text = plt.text(R_x, R_y, '$({0:.2f}, {1:.2f})$'.format(R_x, R_y), horizontalalignment='right', verticalalignment='center', fontsize=15, color='orange') title = 'Stereographic Projection: $\mathbf{S^{1}} \setminus \{(0, 1)\}$ ' \ 'to $\mathbf{R}$' plt.title(title, color='orange', y=1.09) plt.grid(False) plt.gca().spines['left'].set_visible(False) plt.gca().spines['top'].set_visible(False) plt.gca().spines['right'].set_visible(False) plt.gca().spines['bottom'].set_visible(False) plt.gca().set_xticks([]) plt.gca().set_yticks([]) anim = [] anim.append(animation.FuncAnimation(fig, update_plot, fargs=(text, plot, plot1, plot2, plot3), frames=np.arange(0, 2 * np.pi, 0.01), interval=50, repeat=True)) plt.show() if __name__ == '__main__': create_animation() 的优先级高于AND。在您的OR语句周围加上括号。 https://docs.microsoft.com/en-us/sql/t-sql/language-elements/operator-precedence-transact-sql?view=sql-server-2017

OR