count.md 1.6 KB
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# count 练习

Joe 建立了一个名为items的表

```
mysql> select * from items;
+----+-----------+
| id | item      |
+----+-----------+
|  1 |         2 |
|  2 |      NULL |
|  3 |         9 |
|  4 | 534214123 |
+----+-----------+
```

当他执行

fix bug  
张志晨 已提交
19
```sql
20 21
select count(*), count(item) 
from items;
M
Mars Liu 已提交
22 23 24 25
```

会得到什么结果?

M
Mars Liu 已提交
26 27
<hr/>

F
feilong 已提交
28
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill){target="_blank"}。
F
feilong 已提交
29

F
feilong 已提交
30 31
* `show databases;` 列出所有数据库
* `show tables;` 列出所有表
M
Mars Liu 已提交
32

M
Mars Liu 已提交
33 34 35
## 答案

```
M
Mars Liu 已提交
36 37 38 39 40 41
+----------+-------------+
| count(*) | count(item) |
+----------+-------------+
|        4 |           3 |
+----------+-------------+
1 row in set (0.00 sec)
M
Mars Liu 已提交
42 43 44 45 46 47 48
```

## 选项

### A

```
M
Mars Liu 已提交
49 50 51 52 53 54
+----------+-------------+
| count(*) | count(item) |
+----------+-------------+
|        4 |        NULL |
+----------+-------------+
1 row in set (0.00 sec)
M
Mars Liu 已提交
55 56 57 58 59
```

### B

```
M
Mars Liu 已提交
60 61 62 63 64 65
+----------+-------------+
| count(*) | count(item) |
+----------+-------------+
|        3 |           3 |
+----------+-------------+
1 row in set (0.00 sec)
M
Mars Liu 已提交
66 67 68 69 70
```

### C

```
M
Mars Liu 已提交
71 72 73 74 75 76
+----------+-------------+
| count(*) | count(item) |
+----------+-------------+
|        4 |           4 |
+----------+-------------+
1 row in set (0.00 sec)
M
Mars Liu 已提交
77 78 79 80 81
```

### D

```
M
Mars Liu 已提交
82 83 84 85 86 87
+----------+-------------+
| count(*) | count(item) |
+----------+-------------+
|     NULL |        NULL |
+----------+-------------+
1 row in set (0.00 sec)
M
Mars Liu 已提交
88 89 90 91 92
```

### E

```
M
Mars Liu 已提交
93 94 95 96 97 98
+----------+-------------+
| count(*) | count(item) |
+----------+-------------+
|        4 |           0 |
+----------+-------------+
1 row in set (0.00 sec)
M
Mars Liu 已提交
99
```