首页 > 数据库技术 > 详细

Sql 复习(2)

时间:2019-04-05 16:11:35      阅读:129      评论:0      收藏:0      [点我收藏+]

Sql 中 不等于 可以用 以下方式表示:

select * from [TableName] where not id = 1; (注意不能写成 select * from [TableName] where id not = 1;)

select * from [TableName] where id != 1;

select * from [TableName] where id <> 1;(最常用)

通配符:

%表示匹配0个,1个或多个字符。

select * from [TableName] where address like ‘%‘ 不会检索出address值为null的行。

_表示只匹配一个字符,不能多也不能少。

集合通配符[]:(貌似只有微软的数据库支持,以下是Sqlserver中的例子,Access的写法不太一样)

找出所有名字以G或X开头的用户。

select * from Users where name like ‘[GX]%‘

否定上面的语句有三种写法:

1. select * from Users where name like ‘[^GX]%‘

2. select * from Users where name not like ‘[GX]%‘

3. select * from Users where not name like ‘[GX]%‘(这个是not的通用语法,表示否定后面的这条语句)

注意:不要过度使用通配符,如果能用其他操作符的能达到相同目的,请使用其他操作符。

如果确实需要使用通配符,也尽量不要把它们用在搜索的开始处,因为这样搜索是最慢的。

Sql 复习(2)

原文:https://www.cnblogs.com/grady1028/p/10658853.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!