让运维不加班,从一套On-Call响应机制开始!
735
2022-10-16
SQL基础-like
使用字符匹配like或not like可以把表达式与字符串进行比较,实现对字符串的模糊查询。
%表示包含零个或多个字符的任意字符串
_ (下划线)表示任何单个字符
like的语法:
select column_name(s)from table_namewhere column_name [not] like 'string'--string 表示进行比较的字符串
示例:
表的定义如下:
create table [dbo].[Students]( [StuId] [int]not null, [StuName] [nvarchar](50) not null, [StuDept] [nvarchar](50) not null, [StuAge] [int] not null,)
1.普通查询如下:
select * from [EntryTestDB].[dbo].[Students]
select * from [EntryTestDB].[dbo].[Students]where [StuName] like '张%'
3.找出所有姓张单名一个字的所有信息:
select * from [EntryTestDB].[dbo].[Students]where [StuName] like '张_'
4.找出不姓张的所有学生的信息
select * from [EntryTestDB].[dbo].[Students]where [StuName] not like '张%'
发表评论
暂时没有评论,来抢沙发吧~