MYSQLOR与AND⼀起的⽤法
MYSQL OR与AND⼀起的⽤法
在MySQL中 or 的⽤法
-- 查询结果是id = 2且age = 20或者id=1
SELECT * from student WHERE id = 1or id = 2AND age = 20;
-- 查询结果是 id=1或id=2 且age = 20
SELECT * from student WHERE (id = 1or id = 2 ) AND age = 20;
犯错记录:要求查出 INVOICE_TITLE like ‘12%’或者CLIENT_NAME LIKE ‘%12%’的数据,结果前台⼀直报请求超时,发现数据多了将近20倍,SQL如下
SELECT
*
FROM
ewin_should_receive sr,
ewin_client_snap cs
WHERE
sr.client_snap_id = cs.id
eval是做什么的AND sr.b_enable = '1'
AND cs.INVOICE_TITLE LIKE'%12%'
OR cs.CLIENT_NAME LIKE'%12%'
//正确SQL
SELECT
*
FROM
ewin_should_receive sr,
ewin_client_snap cs
WHERE
sr.client_snap_id = cs.id
AND sr.b_enable = '1'
AND (
cs.INVOICE_TITLE LIKE'%12%'
OR cs.CLIENT_NAME LIKE'%12%'
)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论