zoukankan      html  css  js  c++  java
  • MYSQL OR与AND同时出现的用法

    表中数据

    MySQL中or和and的用法

    SELECT * from student WHERE id = 1 or id = 2 AND age = 20;
    -- 查询结果是id = 2且age = 20或者id=1

    SELECT * from student WHERE (id = 1 or id = 2 ) AND age = 20;
    -- 查询结果是 id=1或id=2 且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
    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%'
    )
    

     

    原文

  • 相关阅读:
    监听
    用户管理
    oracle网络
    实例 参数
    存储管理
    oracle 体系
    实例
    修改
    集合操作
    17.08.18
  • 原文地址:https://www.cnblogs.com/sueyyyy/p/10448836.html
Copyright © 2011-2022 走看看