2_02_MSSQL课程_where查询和like模糊查询

1.where 条件过滤

  常见的表达式过滤:比如: select * from 表 where Id>10;

  多条件过滤: and or not    (优先级:not > and > or)       !  &&     || 

  select * from SalesLT.Customer
  where 
  CustomerID>100 and Title<>'MS.' or MiddleName='N.'          --<>非的意思     先运算 <>, 再运算 and,最后运算 or

  区间过滤:between and       和    in        

select * from SalesLT.Customer
where CustomerID>20 and CustomerID<50;
where CustomerID between 20 and 50;

 

  模糊查询

  要求:把所有FirstName 中以Jac开头的 数据都查询出来。

select * from SalesLT.Customer
     where FirrstName like 'Jac%'

   where FirrstName like '_0%' 
   where FirrstName like '%''%' 
   where FirrstName like '%[0-9]%' 
   where CompanyName like '%\[%'escape'\' 

    like 查询语法

    针对字符产查询的通配符:  % _   [] 

     正则表达式一致,其中%表示匹配任何零个字符,一个字符或多个字符。  _表示匹配一个字符,只是一个字符。 

     '%[0-9]%'   0到9           ‘%[0,9]%’   0或9

    特殊字符转义。 ‘’ 和[     

      ‘%''%’两个单引号表示一个单引号;  ‘%[[]%’  两个中括号表示一个中括号     ‘%\[%’escape'\'(不建议使用)

  空值处理:

    null为不知道的意思

    列=null的结果 用 is null表示   

select * from SalesLT.Customer where MiddleName is null

    is null 和 is not null

 

posted @ 2019-11-11 11:54  MR_L先生  阅读(297)  评论(0编辑  收藏  举报