来自INNER JOIN的SQL计数

如何通过分组从内部联接中选择计数?
SELECT COUNT(table1.act) FROM table1
INNER JOIN table2 ON table1.act = table2.act
GROUP BY table1.act

这将返回table2中找到的act的计数.

添加

SELECT table1.act,COUNT(table1.act) AS test

返回

act     test
------- ----
17682   3
17679   3
17677   3
11636   1
11505   1

我想收到行为总数的计数.

所以我想得到5.你能帮忙吗?

解决方法

您可以将该查询包装到另一个查询中:
SELECT COUNT(*) FROM (
    SELECT COUNT(table1.act) AS actCount FROM table1
    INNER JOIN table2 ON table1.act = table2.act
    GROUP BY table1.act
) t

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...