[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
格式:SELECT 字段 FROM 表 WHERE 字段 Like 条件
SQL提供了四种匹配模式
1、_: 表示任意单个字符,用于匹配单个任意字符
例1:查询姓为张,名字只有2个字的用户
select * from user where name like '张_' (可匹配张兵、张大、张胜...)
2、%:表示任意0个或多个字符,用于匹配任意类型和长度的字符,中文需要使用两个百分号(%%)表示
例1:查询名字中含有兵的用户
select * from user where name like '%兵%' (可匹配王小兵、王兵、王兵西...)
例2:查询名字中含有小和兵的用户
select * from user where name like '%小%' and name like '%兵%' (可匹配小张兵、张兵小、张小兵等)
例3: 查询名字中含有小兵的用户
select * from user where name like '%小兵%' (可匹配王小兵、小兵张...)
例4:用户表user_profile(device_id , gender 性别, age 年龄, university 学校, province 省份)
请筛选出学校名满足以下所有条件的用户,输出关键字段信息:
以“北京”或“上海”开头;
以“学院”或“校区”结尾;
包含“职业”或“专科”或“成人”
select id ,device_id ,university
from user_profile
where (university like '北京%' or university like '上海%' )
and (university like '%学院' or university like '%校区' )
and (university like '%职业%' or university like '%专科%' or university like
'%成人%' )
3、[ ]:指定一个字符、字符串或范围,要求所匹配对象为它们中的任一个
例1:查询姓为朱、张、王,名字为兵用户
select * from user where name like '[朱张王]兵' (可匹配朱兵、张兵、王兵)
例2:查询姓为张,名字为1-9的用户
select * from user where name like '张[1-5]' (可匹配张1、张2、张3...)
例3:查询姓为张,名字为a-z的用户
select * from user where name like '张[a-c]' (可匹配张a、张b、张c...)
4、[^ ] :表示不在括号所列之内的单个字符
例1:查询姓不为朱、张、王,名字为兵用户
select * from user where name like '[^朱张王]兵' (可匹配李兵、陈兵)
例2:查询姓为张,名字为1-5的用户
select * from user where name like '张[^1-5]' (可匹配张6、张7...)
例3:查询姓为张,名字不为a-c的用户
select * from user where name like '张[^a-c]' (可匹配张d、张e...)