栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

MySQL或/和优先级?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MySQL或/和优先级?

MySQL文档有一个很好的页面,其中包含有关哪些运算符优先的信息。

在该页面上,

12.3.1。运算符优先级

运算符优先级从最高优先级到最低优先级显示在以下列表中。一起显示在一行上的运算符具有相同的优先级。

INTERVALBINARY, COLLATE!- (unary minus), ~ (unary bit inversion)^*, /, DIV, %, MOD-, +<<, >>&|= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, INBETWEEN, CASE, WHEN, THEN, ELSENOT&&, ANDXOR||, OR= (assignment), :=

所以你原来的查询

Select    *from tablename where    display = 1    or display = 2    and content like "%hello world%"    or tags like "%hello world%"    or title = "%hello world%"

将被解释为

Select    *from tablename where     (display = 1)    or (        (display = 2)        and (content like "%hello world%")    )    or (tags like "%hello world%")    or (title = "%hello world%")

如有疑问,请使用括号将您的意图弄清楚。虽然MySQL页面上的信息很有帮助,但如果再次访问该查询,可能不会立即显而易见。

您可能会考虑以下内容。请注意,我已将更改

title = "%hello world%"
title like "%helloworld%"
,因为它更适合您所描述的目标。

Select    *from tablename where    (        (display = 1)        or (display = 2)    ) and (        (content like "%hello world%")        or (tags like "%hello world%")        or (title like "%hello world%")    )


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/386380.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号