时间:2021-07-01 10:21:17 帮助过:30人阅读
要了解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)
现在根据上面的表,要算在此表中的行数,那么可以做如下的假设:
mysql>SELECT COUNT(*) FROM employee_tbl ; +----------+ | COUNT(*) | +----------+ | 7 | +----------+ 1 row in set (0.01 sec)
同样地,想数一数的话就可以计算一下如下记录为Zara的数量:
mysql>SELECT COUNT(*) FROM employee_tbl -> WHERE name="Zara"; +----------+ | COUNT(*) | +----------+ | 2 | +----------+ 1 row in set (0.04 sec)
注意: 所有的SQL查询是区分大小写的,所以它并没有任何区别,如果你给ZARA或Zara在where条件中。