Sql中的谓词

谓词:
指返回值为真值的函数
如一下函数
Like Betweent Is Null Is Not Null In Exist
①Like
模糊查询
select * from datatable where tableColumn like %ddd%
% 代表0个以上的任意字符,_代表任意 一个 字符
②Between
范围查询
Between a AND b 的特点是是会包含a 和 b这两个临界值,如果不想让结果包含临界值,就需要使用 <>
③ Is Null 和 Is Not Null
值为Null时 不能使用=,只能使用Null
④In/Not in
Or的简单用法
使用In 或者Not In 无法选取出Null数据
In/Not in谓词具有一个独特的用法:使用子查询作为其参数,也就是说能够将表作为In的参数
⑤Exists谓词
Exists 的使用比较困难,主要使用因为使用了Not Exists的Select语句,所以基本上用IN/Not In来代替
⑴Exists使用方法
判断是否存在。存在true,不存在False
select c1,c2 from table1 as t1 where Exists (select * from table2 as t2 where t2.c1 =’–’ and t2 .c2=t1.c3);
(用 IN:select c1,c2 from table1 where c3 in (select c2 in table2 where c1=’–’)
exist 通常都用于关联子查询,exist只关心结果在或者不在
(关联名称的作用域:内部子查询设定的关联名称,只能在子查询的内部使用,即内部可以看到外部,外部看不到内部)

猜你喜欢

转载自blog.csdn.net/Good_StudyDaydayUp/article/details/82963600