1 COUNT() 函数
count函数如果指定列,如count(province),会忽略NULL的值 ,如果不指定列,使用count(*),所有记录都不会忽略。
mysql> select * from fruits;
+------+------+------------+---------+----------+
| f_id | s_id | f_name | f_price | province |
+------+------+------------+---------+----------+
| a1 | 101 | apple | 5.20 | HeNan |
| b1 | 101 | blackberry | 10.20 | ShanDong |
| b11 | 101 | apple | 4.00 | NULL |
| bs1 | 102 | orange | 11.20 | NULL |
+------+------+------------+---------+----------+
4 rows in set (0.00 sec)
mysql> select count(*) as total from fruits;
+-------+
| total |
+-------+
| 4 |
+-------+
1 row in set (0.00 sec)
mysql> select count(province) from fruits;
+-----------------+
| count(province) |
+-----------------+
|