francisblogs

 一、SQL入门语句之LIKE

LIKE用来匹配通配符指定模式的文本值。如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1。这里有两个通配符与 LIKE 运算符一起使用,百分号(%)代表零个、一个或多个数字或字符。下划线(_)代表一个单一的数字或字符。这些符号可以被组合使用。

1、查找字段A以AAA开头的任意值

  select * from table_name where 字段A like \'AAA%\'

2、查找字段A任意位置包含AAA的任意值

  select * from table_name where 字段A like \'%AAA%\'

3、查找字段A第二位和第三位为 AA 的任意值

  select *from table_name where 字段A like \'_AA%\'

4、查找字段A以 A 开头,且长度至少为 3 个字符的任意值

  select * from table_name where 字段A like \'A_%_%\'

 5、查找字段A以 A 结尾的任意值

  select *from table_name where 字段A like \'%A\'

6、查找字段A第二位为 A,且以 B 结尾的任意值

  select *from table_name where 字段A like \'_A%B\'

 7、查找字段A长度为 5 位数,且以 A 开头以 B 结尾的任意值(A,B中间三个下划线)

  select *from table_name where 字段A like \'A___B\'

 二、SQL入门语句之GLOB

 GLOB是用来匹配通配符指定模式的文本值。如果搜索表达式与模式表达式匹配,GLOB 运算符将返回真(true),也就是 1。与 LIKE 运算符不同的是,GLOB 是大小写敏感的,通配符有星号(*)代表零个、一个或多个数字或字符。问号(?)代表一个单一的数字或字符。这些符号可以被组合使用,它遵循 UNIX 的语法。

1、查找字段A以AAA开头的任意值

  select * from table_name where 字段A GLOB \'AAA*\'

2、查找字段A任意位置包含AAA的任意值

  select * from table_name where 字段A GLOB \'*AAA*\'

3、查找字段A第二位和第三位为 AA 的任意值

  select *from table_name where 字段A GLOB \'?AA*\'

4、查找字段A以 A 开头,且长度至少为 3 个字符的任意值

  select * from table_name where 字段A GLOB \'A?*?*\'

 5、查找字段A以 A 结尾的任意值

  select *from table_name where 字段A GLOB \'*A\'

6、查找字段A第二位为 A,且以 B 结尾的任意值

  select *from table_name where 字段A GLOB \'?A*B\'

 7、查找字段A长度为 5 位数,且以 A 开头以 B 结尾的任意值(A,B中间三个下划线)

  select *from table_name where 字段A GLOB \'A???B\'

 

三、SQL入门语句之LIMIT

LIMIT用于限制由 SELECT 语句返回的数据数量。

1、从数据库表中获取 n 条数据

  select *from table_name limit n

2、从数据库表中第 m 条开始获取 n 条数据

  select *from table_name limit n offset m

3、从数据库表中获取满足特定条件的 n 条数据

  select *from table_name where [condition] limit n

4、从数据库表中满足条件的第 m 条开始获取 n 条数据

  select *from table_name where [condition] limit n offset m

 

 


分类:

技术点:

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2021-11-19
  • 2021-11-27
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-16
  • 2022-01-11
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案