SQL 操作符
来源:互联网 发布:mac口红免税店价格 编辑:程序博客网 时间:2024/06/15 16:20
1,LIKE:检查列值是否匹配指定的模式;模式字符串中可以使用普通字符以及两个通配符:_和%。
_ 代表任意单个字符;
% 代表任意长度(长度可以为0)的字符串
因为_和%在模式字符串中具有特殊含义,因此如果要匹配这两个字符,可使用escape选项来标识这些字符。
select *from promotions t where name like '%\%%' escape '\'
(将\声明为符号而不带入值中用于搜索)
注:NOTLIKE表示不匹配指定的模式。
当列值为空时,永远返回false。
eg:
SQL>select * from customers where first_name like'_o%';
CUSTOMER_IDFIRST_NAME LAST_NAME DOB PHONE
--------------------- ---------- -------------- ------------
SQL>select * from customers where first_name like'_o';(o后面没有字母了)
未选定行
eg:
SQL>select * from customers where first_name like'%e%';
CUSTOMER_IDFIRST_NAME LAST_NAME DOB PHONE
--------------------- ---------- -------------- ------------
SQL>select * from customers where last_name like'%e%';
CUSTOMER_IDFIRST_NAME LAST_NAME DOB PHONE
--------------------- ---------- -------------- ------------
SQL>select * from customers where last_name like '%e%' and first_namelike '%e%';(两个关键字都包含e的项目)
CUSTOMER_IDFIRST_NAME LAST_NAME DOB PHONE
--------------------- ---------- -------------- ------------
eg:
SQL>select * from promotions where name like '%\%%';(%%效果一样)
PROMOTION_IDNAME DURATION
---------------------------------------------------------------------------------------------------------------------
2, 确定取值的集合:
SQL>select * from employees where employee_id in (2,4);(将2行和4行的数值一起返回)
SQL>select * from employees where employee_id not in (2,4);(除了2和4行的数值)
注意:如果值列表中含有null,则notin的运算结果永远为false,那么一条记录也不会被检索出来。如下:
selectproduct_id,product_type_id,name
fromproducts
eg:
SQL>where product_type_id not in (1,2,null);
未选定行
(若无not 只是1,2,null 则若有数值则返回数值)
注:select对于列进行选择 where 对于行进行选择
附加的小尾巴 :
1=1的用法小实例
sql = select* from student where 1=1
if(sid !=null){sql += " and sid = 123";}
if(name !=null){sql += " and name like '%name%'";}
说明
这样子写就可以省略下面繁琐的搜索了
select *from student where sid = 123;
select *from student where name like '%name%';
select *from student where age = 22;
3, BETWEEN … AND …
(包括左边和右边的闭区间)
eg:
SQL>select * from products whereproduct_id between 8 and 10;
SQL>select * from products where name between 'A%' and 'Z%';(同样支持字符串但是要将范围写清楚 日期也同样使用,但是格式要写清楚)
用于确定取值范围(闭区间)。
4, IS NULL涉及空值的查询
“IS NULL”不能用 “= NULL” 代替
IS NOTNULL
SQL>select * from customers where dob is null;
下面两个判断用于BINARY_FLOAT和BINARY_DOUBLE类型的列:
5, 用于判断列取值是否非数字
IS NAN 是非数字- 不是数字
IS NOT NAN不是非数字-是数字
SQL>select * from products where product_type_id is notnan;
6, ISINFINITE 判断列取值是否无穷大
IS NOTINFINITE
0 0
- SQL 操作符
- SQL 收藏------------SQL操作全集
- sql 表连接, union
- sql sum 空或0
- SQL Server 2005 SQL 注入
- Native SQL 整理
- oracle sql 语句
- sql server 作业题
- pl/sql 初使用
- SQL Server 2008 …
- SQL Server CROSS …
- SQL Server DATEDIFF() 函数
- SQL SERVER 2005 …
- sql 调优 工具 准备
- Create SQL Agent …
- SQL SERVER DMO 简介
- HANA Basic SQL 01
- HANA Basic SQL 02
- spring mvc+hibernate 实现事务管理(全注解版)
- Java Swing 中插入图片背景
- 我所知道px、dpi、dp、dip、sp、in、pt之间的差别
- Orcle SQL基础命令语句
- select 查询语句的小尾巴~~~…
- SQL 操作符
- SQL 排序
- java-Transient关键字、Volatile关键字介绍和序列化、反序列化机制、单例类序列化
- SQL 多表联合查询
- vector和list的一些基本用法
- SQL函数(-)
- HDU 5011(博弈)
- SQL函数(二)
- java 线程synchronized 线程同步