MySQL必知必会l语句总结(二)

  • 使用where 语句过滤数据
    最简单的语句select prod_name,prod_price from products where prod_price=2.5;查询prod_price为2.5的数据

在同时使用 ORDER BY 和 WHERE 子句时,应
该让 ORDER BY 位于 WHERE 之后,否则将会产生错误
这是where语句支持的操作符
MySQL必知必会l语句总结(二)

下面给出一些案例由于这些运算符大部分使用方式都是相同的我只给出几个特别的案例供大家参考
select prod_name,prod_price from products where prod_price < 10 ;查询prod_price价格小于10的
select vend_id,prod_name from products where vend_id <> 1003;查询ID不是1003的也可以这样使用select vend_id,prod_name from products where vend_id != 1003;
select prod_name,prod_price from products where prod_price between 5 and 10;查询某个区间
空值检查select prod_name from products where prod_price is null;

NULL 与不匹配 在通过过滤选择出不具有特定值的行时,你
可能希望返回具有 NULL 值的行。但是,不行。因为未知具有
特殊的含义,数据库不知道它们是否匹配,所以在匹配过滤
或不匹配过滤时不返回它们。
因此,在过滤数据时,一定要验证返回数据中确实给出了被
过滤列具有 NULL 的行