mysql> select * from result;

+------+---------+-------+
| name | subject | score |
+------+---------+-------+
| a | a-1 | 60 |
| b | b-1 | 70 |
| c | c-1 | 80 |
| d | d-1 | 90 |
| a | aa-1 | 40 |
| a | aaa-1 | 55 |
| b | bb-1 | 10 |
| b | bbb-1 | 70 |
| c | cc-1 | 30 |
| c | ccc-1 | 60 |
| d | dd-1 | 100 |
| d | ddd-1 | 99 |
+------+---------+-------+
12 rows in set (0.00 sec)


数据库中对空值的处理:sum()不计算,count()认为没有此项;

#COUNT 是对查询中符合条件的结果(或记录)的个数
mysql> select name,count(score) from result;
+------+--------------+
| name | count(score) |
+------+--------------+
| a | 12 |
+------+--------------+
1 row in set (0.00 sec)

#SUM是对符合条件的记录的数值列求和
mysql> select name,sum(score) from result;
+------+------------+
| name | sum(score) |
+------+------------+
| a | 764 |
+------+------------+
1 row in set (0.00 sec)

相关文章:

  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2021-08-09
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2021-10-02
相关资源
相似解决方案