From 725a7fe61e347af12e5e8182af940297a4bd1697 Mon Sep 17 00:00:00 2001 From: Xicheng Guo Date: Thu, 7 Nov 2024 14:18:45 +0800 Subject: [PATCH] update docs --- src/.vitepress/sidebars/sqlite.yaml | 22 +++ .../sqlite/core-concepts/select-statement.md | 167 ++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 src/database/sqlite/core-concepts/select-statement.md diff --git a/src/.vitepress/sidebars/sqlite.yaml b/src/.vitepress/sidebars/sqlite.yaml index 2779d21..f96e57c 100644 --- a/src/.vitepress/sidebars/sqlite.yaml +++ b/src/.vitepress/sidebars/sqlite.yaml @@ -62,5 +62,27 @@ link: /database/sqlite/core-concepts/update-statement#更新所有行 - text: 更新指定行 link: /database/sqlite/core-concepts/update-statement#更新指定行 + - text: Select 语句 + link: /database/sqlite/core-concepts/select-statement + items: + - text: 基本语法 + link: /database/sqlite/core-concepts/select-statement#基本语法 + - text: Where 子句 + link: /database/sqlite/core-concepts/select-statement#where-子句 + items: + - text: 比较 + link: /database/sqlite/core-concepts/select-statement#比较 + - text: 逻辑 + link: /database/sqlite/core-concepts/select-statement#逻辑 + - text: IN + link: /database/sqlite/core-concepts/select-statement#in + - text: Between And + link: /database/sqlite/core-concepts/select-statement#between-and + - text: Exists + link: /database/sqlite/core-concepts/select-statement#exists + - text: Is Null + link: /database/sqlite/core-concepts/select-statement#is-null + - text: Like 子句 + link: /database/sqlite/core-concepts/select-statement#like-子句 \ No newline at end of file diff --git a/src/database/sqlite/core-concepts/select-statement.md b/src/database/sqlite/core-concepts/select-statement.md new file mode 100644 index 0000000..2eaec3a --- /dev/null +++ b/src/database/sqlite/core-concepts/select-statement.md @@ -0,0 +1,167 @@ +# Select 语句 + +## 基本语法 + +::: code-group + +```sql [语法] +SELECT column1, column2, ... +FROM table_name; +``` + +```sql [实例] +SELECT name, age +FROM students; +``` + +::: + +## Where 子句 + +### 比较 + +::: code-group + +```sql [大于] +select * from students where age > 20; +``` + +```sql [小于] +select * from students where age < 20; +``` + +```sql [大于等于] +select * from students where age >= 20; +``` + +```sql [小于等于] +select * from students where age <= 20; +``` + +```sql [等于] +select * from students where age = 20; +``` + +```sql [不等于] +select * from students where age != 20; +``` + +::: + +### 逻辑 + +::: code-group + +```sql [AND] +select * from students where age > 20 and name = 'John'; +``` + +```sql [OR] +select * from students where age > 20 or name = 'John'; +``` + +```sql [NOT] +select * from students where not age > 20; +``` + +::: + +### IN + +::: code-group + +```sql [IN] +select * from students where age in (20, 21, 22); +``` + +```sql [NOT IN] +select * from students where age not in (20, 21, 22); +``` + +::: + +### Between And + +::: code-group + +```sql [BETWEEN] +select * from students where age between 20 and 30; +``` + +```sql [NOT BETWEEN] +select * from students where age not between 20 and 30; +``` + +::: + +### Exists + +::: code-group + +```sql [EXISTS] +select * from students where exists ( + select * from teachers where students.teacher_id = teachers.id +); +``` + +```sql [NOT EXISTS] +select * from students where not exists ( + select * from teachers where students.teacher_id = teachers.id +); +``` + +::: + +### Is Null + +::: code-group + +```sql [IS NULL] +select * from students where name is null; +``` + +```sql [IS NOT NULL] +select * from students where name is not null; +``` + +::: + +## Like 子句 + +Like 用来匹配通配符指定模式的文本值。 + +Like 通常与两个通配符一起使用: + +- 百分号(%):代表零个、一个或多个字符。 +- 下划线(\_):代表一个单一的字符。 + +::: code-group + +```sql [LIKE] +select * from students where name like 'J%'; +``` + +```sql [NOT LIKE] +select * from students where name not like 'J%'; +``` + +```sql [LIKE] +select * from students where name like 'J_n'; +``` + +```sql [NOT LIKE] +select * from students where name not like 'J_n'; +``` + +::: + +| 语句 | 描述 | +| --------------------------- | ----------------------------------- | +| `WHERE SALARY LIKE '200%'` | 查找以 200 开头的任意值 | +| `WHERE SALARY LIKE '%200'` | 查找以 200 结尾的任意值 | +| `WHERE SALARY LIKE '%200%'` | 查找包含 200 的任意值 | +| `WHERE SALARY LIKE '_00%'` | 查找第二位是 0,第三位是 0 的任意值 | +| `WHERE SALARY LIKE '2_%_%'` | 查找以 2 开头且长度至少为 3 的值 | +| `WHERE SALARY LIKE '2__'` | 查找以 2 开头且长度为 3 的值 | +| `WHERE SALARY LIKE '2%5'` | 查找以 2 开头且以 5 结尾的值 | +| `WHERE SALARY LIKE '2___5'` | 查找以 2 开头且长度为 5 的值 |