V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
cs5117155
V2EX  ›  MySQL

求一个 mysql 语句同时满足两列的条件进行筛选

  •  
  •   cs5117155 · 2021-01-23 17:29:29 +08:00 · 1587 次点击
    这是一个创建于 1188 天前的主题,其中的信息可能已经有所发展或是发生改变。
    SELECT `o`.`id`,`o`.`pay_type`,`o`.`operation_id`,`o`.`order_no` FROM `pay_auth_log` `o` WHERE  `o`.`status` < 99  AND `pay_status` <= 1;
    

    这条语句怎么改为,当pay_type=2 && operation_id为空的时候就过滤改条信息,但是pay_type=1时,operation_id为空时,该记录需要展示出来。 截图

    5 条回复    2021-01-26 22:19:59 +08:00
    eason1874
        1
    eason1874  
       2021-01-23 17:33:40 +08:00   ❤️ 1
    `pay_type` = 1 OR (`pay_type` = 2 AND `operation_id` IS NOT NULL)
    easonzhang666
        2
    easonzhang666  
       2021-01-23 17:37:28 +08:00
    and ((xx ) or (xx))
    cs5117155
        3
    cs5117155  
    OP
       2021-01-23 18:01:46 +08:00
    good
    deargodfrey
        4
    deargodfrey  
       2021-01-23 18:06:42 +08:00 via Android
    mysql 能用 not 吗如果有的话就只要加个 AND NOT (paytype=2 and operationid is null)
    cs5117155
        5
    cs5117155  
    OP
       2021-01-26 22:19:59 +08:00
    @deargodfrey 这个也不错
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5444 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:53 · PVG 16:53 · LAX 01:53 · JFK 04:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.