mysql> select COUNT(*), * from help_keyword;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* from help_keyword' at line 1
Run Code Online (Sandbox Code Playgroud)
这个没有:
mysql> select COUNT(*), help_keyword.* from help_keyword;
+----------+-----------------+------+
| COUNT(*) | help_keyword_id | name |
+----------+-----------------+------+
| 452 | 0 | JOIN |
+----------+-----------------+------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
这是为什么?
因为通过使用Count(*)您告诉数据库您想要聚合查询,因此选择中不包含某些聚合函数(如count,min,max等)的任何列或表达式用于定义"桶"聚合将在...上执行.如果有任何此类表达式,通常还需要包含一个Group By子句来显式列出这些列/表达式.通过包含表的所有列(这就是*所做的),你要说的是表中的每一行的聚合,这没有意义.(在任何适当的关系tbale中,总会只有一行匹配该行的每个值)
| 归档时间: |
|
| 查看次数: |
1315 次 |
| 最近记录: |