• MariaDB 条件语句WHERE


    MariaDB 条件语句WHERE

    WHERE Clause Operators Operator Description

    = Equality
    <> Nonequality
    != Nonequality
    Less than
    <= Less than or equal to 

    > Greater than

    >= Greater than or equal to BETWEEN Between two specified values 


    BETWEEN AND

    (jlive)[crashcourse]>SELECT prod_name,prod_price FROM products WHERE prod_price BETWEEN 5 AND 10;

    +----------------+------------+

    | prod_name      | prod_price |

    +----------------+------------+

    | .5 ton anvil   |       5.99 |

    | 1 ton anvil    |       9.99 |

    | Oil can        |       8.99 |

    | TNT (5 sticks) |      10.00 |

    | Bird seed          10.00 |

    +----------------+------------+

    5 rows in set (0.00 sec)


    通配LIKE(_%)

    (jlive)[crashcourse]>SELECT prod_name,prod_price FROM products WHERE prod_price BETWEEN 5 AND 10 AND prod_name LIKE 'Oil%';

    +-----------+------------+

    | prod_name | prod_price |

    +-----------+------------+

    | Oil can   |       8.99 |

    +-----------+------------+

    1 row in set (0.00 sec)

    (jlive)[crashcourse]>SELECT prod_id, prod_name FROM products WHERE prod_name LIKE '_ ton anvil';

    +---------+-------------+

    | prod_id | prod_name   |

    +---------+-------------+

    | ANV02   | 1 ton anvil |

    | ANV03   | 2 ton anvil |

    +---------+-------------+

     

    2 rows in set (0.00 sec)


    (AND) OR组合

    (jlive)[crashcourse]>SELECT vend_id,prod_name,prod_price FROM products WHERE vend_id = 1002 OR vend_id = 1003 AND prod_price >= 10 ORDER BY prod_price DESC;

    +---------+----------------+------------+

    | vend_id | prod_name      | prod_price |

    +---------+----------------+------------+

      1003 | Safe               50.00 |

      1003 | Detonator          13.00 |

      1003 | TNT (5 sticks) |      10.00 |

      1003 | Bird seed          10.00 |

      1002 | Oil can        |       8.99 |

      1002 | Fuses          |       3.42 |

    +---------+----------------+------------+

    6 rows in set (0.00 sec)


    (jlive)[crashcourse]>SELECT vend_id,prod_name,prod_price FROM products WHERE (vend_id = 1002 OR vend_id = 1003) AND prod_price >= 10 ORDER BY 3 DESC;

    +---------+----------------+------------+

    | vend_id | prod_name      | prod_price |

    +---------+----------------+------------+

      1003 | Safe               50.00 |

      1003 | Detonator          13.00 |

      1003 | TNT (5 sticks) |      10.00 |

      1003 | Bird seed          10.00 |

    +---------+----------------+------------+

     

    4 rows in set (0.00 sec)


    (NOT) IN

    (jlive)[crashcourse]>SELECT vend_id,prod_name,prod_price FROM products WHERE vend_id IN (1002,1003) ORDER BY vend_id;

    +---------+----------------+------------+

    | vend_id | prod_name      | prod_price |

    +---------+----------------+------------+

      1002 | Oil can        |       8.99 |

      1002 | Fuses          |       3.42 |

      1003 | Sling          |       4.49 |

      1003 | TNT (1 stick)  |       2.50 |

      1003 | TNT (5 sticks) |      10.00 |

      1003 | Bird seed          10.00 |

      1003 | Carrots        |       2.50 |

      1003 | Safe               50.00 |

      1003 | Detonator          13.00 |

    +---------+----------------+------------+

    9 rows in set (0.00 sec)


    (jlive)[crashcourse]>SELECT vend_id,prod_name,prod_price FROM products WHERE vend_id NOT IN (1002,1003) ORDER BY vend_id;

    +---------+--------------+------------+

    | vend_id | prod_name    | prod_price |

    +---------+--------------+------------+

      1001 | .5 ton anvil |       5.99 |

      1001 | 1 ton anvil  |       9.99 |

      1001 | 2 ton anvil      14.99 |

      1005 | JetPack 1000 |      35.00 |

      1005 | JetPack 2000 |      55.00 |

    +---------+--------------+------------+

     

    5 rows in set (0.00 sec)


    IS (NOT) NULL

    (jlive)[crashcourse]>SELECT cust_id,cust_email FROM customers;

    +---------+---------------------+

    | cust_id | cust_email          |

    +---------+---------------------+

    |   10001 | ylee@coyote.com     |

    |   10002 | NULL                |

    |   10003 | rabbit@wascally.com |

    |   10004 | sam@yosemite.com    |

    |   10005 | NULL                |

    +---------+---------------------+

    5 rows in set (0.00 sec)

    (jlive)[crashcourse]>SELECT cust_id,cust_email FROM customers WHERE cust_email IS NOT NULL;

    +---------+---------------------+

    | cust_id | cust_email          |

    +---------+---------------------+

    |   10001 | ylee@coyote.com     |

    |   10003 | rabbit@wascally.com |

    |   10004 | sam@yosemite.com    |

    +---------+---------------------+

     

    3 rows in set (0.00 sec)

  • 相关阅读:
    linux下查看当前登陆的用户数目
    uboot能ping通本机无法ping通本机上搭建的虚拟机
    一个时序图描述从用户在浏览器地址栏输入url并按回车,到浏览器显示相关内容的各个过程
    3*0.1 == 0.3 将会返回什么?true 还是 false?
    Floating Point Math
    浮点数在计算机中是如何表示的
    浮点数在计算机中是如何表示的
    Java并发编程:volatile关键字解析
    join的源码
    i++ 是线程安全的吗
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814195.html
Copyright © 2020-2023  润新知