Home > Database > Mysql Tutorial > body text

详细解读MySQL中COUNT函数的用法_MySQL

WBOY
Release: 2016-06-01 13:00:16
Original
900 people have browsed it

MySQL的COUNT函数是最简单的功能,非常有用的计算,预计由一个SELECT语句返回的记录数。

要了解COUNT函数考虑的EMPLOYEE_TBL的的表具有以下记录:

mysql> SELECT * FROM employee_tbl;
+------+------+------------+--------------------+
| id  | name | work_date | daily_typing_pages |
+------+------+------------+--------------------+
|  1 | John | 2007-01-24 |        250 |
|  2 | Ram | 2007-05-27 |        220 |
|  3 | Jack | 2007-05-06 |        170 |
|  3 | Jack | 2007-04-06 |        100 |
|  4 | Jill | 2007-04-06 |        220 |
|  5 | Zara | 2007-06-06 |        300 |
|  5 | Zara | 2007-02-06 |        350 |
+------+------+------------+--------------------+
7 rows in set (0.00 sec)

Copy after login

现在根据上面的表,要算在此表中的行数,那么可以做如下的假设:

mysql>SELECT COUNT(*) FROM employee_tbl ;
+----------+
| COUNT(*) |
+----------+
|    7 |
+----------+
1 row in set (0.01 sec)

Copy after login

同样地,想数一数的话就可以计算一下如下记录为Zara的数量:

mysql>SELECT COUNT(*) FROM employee_tbl
  -> WHERE name="Zara";
+----------+
| COUNT(*) |
+----------+
|    2 |
+----------+
1 row in set (0.04 sec)

Copy after login

注意: 所有的SQL查询是区分大小写的,所以它并没有任何区别,如果你给ZARA或Zara在where条件中。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!