From 48b3d58e51ddc90d21f213c033a4145258dd79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E4=BA=A8=E8=80=80?= <2640788668@qq.com> Date: Wed, 25 Oct 2023 11:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E5=8D=81=E4=BA=94=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\222\214count\347\224\250\346\263\225.md" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "21 \345\215\242\344\272\250\350\200\200/\345\255\220\346\237\245\350\257\242\345\222\214count\347\224\250\346\263\225.md" diff --git "a/21 \345\215\242\344\272\250\350\200\200/\345\255\220\346\237\245\350\257\242\345\222\214count\347\224\250\346\263\225.md" "b/21 \345\215\242\344\272\250\350\200\200/\345\255\220\346\237\245\350\257\242\345\222\214count\347\224\250\346\263\225.md" new file mode 100644 index 0000000..03b4656 --- /dev/null +++ "b/21 \345\215\242\344\272\250\350\200\200/\345\255\220\346\237\245\350\257\242\345\222\214count\347\224\250\346\263\225.md" @@ -0,0 +1,21 @@ +### 子查询三大用法 + + 1. 放在 select 后当列使用,要求子查询单列单行。 + 1. 放在 from 后面 当表使用,要给子查询取别名。 + 3. 放在 where 后面当条件使用 + - 单列单行:此时条件可以直接用 = > < <> 等。 + - 单列多行:就需要使用 in any all 等。 + +### count 的使用 + + 1. count(*) 查询所有,包括 null + 1. count(常量) 查询所有,包括 null + 1. count(列名) 返回列名指定列的记录数,不包括 null + +##### count(*)&count(1)&count(列名)执行效率比较: + +- 如果列为主键,count(列名)效率优于count(1) +- 如果列不为主键,count(1)效率优于count(列名) +- 如果表中存在主键,count(主键列名)效率最优 +- 如果表中只有一列,则count(*)效率最优 +- 如果表有多列,且不存在主键,则count(1)效率优于count(*) \ No newline at end of file -- Gitee