Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如果I';我加入了桌子?_Mysql_Sql - Fatal编程技术网

Mysql 如果I';我加入了桌子?

Mysql 如果I';我加入了桌子?,mysql,sql,Mysql,Sql,假设我有以下代码: SELECT a.id, a.name, w.channel, COUNT(*) num FROM accounts a JOIN web_events w ON a.id = w.account_id GROUP BY a.id, a.name, w.channel ORDER BY num; 函数COUNT(*)实际返回的行数是多少 我猜它应该返回accounts表中所有记录(行)的数量,但情况似乎并非如此。您同时使用了GROUP BY和COUNT。GROUP BY子句

假设我有以下代码:

SELECT a.id, a.name, w.channel, COUNT(*) num
FROM accounts a
JOIN web_events w
ON a.id = w.account_id
GROUP BY a.id, a.name, w.channel
ORDER BY num;
函数
COUNT(*)
实际返回的行数是多少


我猜它应该返回accounts表中所有记录(行)的数量,但情况似乎并非如此。

您同时使用了
GROUP BY
COUNT
GROUP BY
子句对每个帐户和频道的所有记录进行分组,
COUNT()
函数与
GROUP BY
一起计算每个帐户的事件数。

它将返回每个组的编号-a.id、a.name、w.channel

a.id、a.name、w.channel每组的行数。这是
按a.id、a.name、w.channel分组的目的。因此,对于a.id、a.name、w.channel的每个组,它将返回三列组合自身重复的次数,对吗?因此GROUP BY子句类似于创建每个组的子表,以及何时计数(*)在本例中使用,它返回每个子表的行数,对吗?(只是确保我理解正确)好吧,如果使用count而不分组,它将返回select语句中所有行的编号。当您将group by与count一起使用时-它将对每个组进行计数。-这里可能有更正式的解释:)如果我没有将它与GROUPBY子句结合使用,它会返回什么?