zoukankan      html  css  js  c++  java
  • SQL必知必会-04

    过滤数据

    使用where子句

    在检索数据时,很少要检索出说有的数据,通常只需要检索出特定的子集即可,这时就需要指出搜索条件,搜索条件也被称为过滤条件。

    使用where关键字,在from子句之后使用。

    eg:select prod_name prod_price from products where prod_price = 3.49;

    数据过滤不止可以在sql中进行过滤,还可以在应用层也就是Java或者c#等代码中进行过滤,在应用层对检索出来的数据进行循环,得到自己想要的数据。但是这种方法值不建议使用的,会大大降低运行的性能。

    在同时使用order by和where时,应把order by放在where之后,否则会报错。

    where子句操作符

    SQL支持的条件操作符

    = <> != < <= !< > >= !> between  is null

    检查单个值

    eg:select prod_name, prod_price from Products where pro_price < 10; 检索pro_price列中值小于10的数据。

    不匹配检查

    eg:select vend_id, prod_name from products where vend_id <> 'dll1';

    ps:在sql中字符串需要单引号进行限定

    范围值检查

    在查询某个范围的值时,可以使用between操作符

    eg:select prod_name, prod_price from Products where prod_price between 5 and 10;查询prod_price 列中值在5到10之间的数据。

    空值检查

    ps:null 与 字段0、空字符串、空格不同

    eg:select prod_name from products where prod_price is null;  检索prod_price列中值为null的数据。

  • 相关阅读:
    基数排序学习
    桶排序学习
    计数排序-不基于比较O(n)
    基尼系数
    拉普拉斯进行特征选择
    int ,long long等范围
    Codeforces780C
    51 Nod 1119
    字典树入门
    POJ 2531 暴力深搜
  • 原文地址:https://www.cnblogs.com/sunshine-2018/p/11416297.html
Copyright © 2011-2022 走看看