SQL查询:如何将计数函数结果组合到select查询中?

SQL查询:如何将计数函数结果组合到select查询中?,sql,Sql,我想将AccountCancellation\u进程中的count(*)组合到上面的内部join语句中,这样查询将给出特许经营表中特许经营名称、首字母缩写、StoreNo的结果,以及AccountCancellation\u进程中Store\Num的结果,其中total records和total records with Progress列不为null 如何将查询结果与计数函数结果相结合 谢谢。给计数取别名(*),然后用一个和(别名)像这样我想这就是你想要的。 我创建了两个表值相关子查询,以根

我想将AccountCancellation\u进程中的count(*)组合到上面的内部join语句中,这样查询将给出特许经营表中特许经营名称、首字母缩写、StoreNo的结果,以及AccountCancellation\u进程中Store\Num的结果,其中total records和total records with Progress列不为null

如何将查询结果与计数函数结果相结合


谢谢。

给计数取别名(*),然后用一个和(别名)

像这样我想这就是你想要的。 我创建了两个表值相关子查询,以根据内部联接表中存储的编号获取数据。然后我根据门店号加入他们。这样,distinct将起作用。但是,您也可以只使用相关的子查询来完成select部分中的计数。但我担心这种方法可能行不通

select distinct Franchise.FranchiseName, Franchise.Initials, Franchise.StoreNo, AccountCancellation_Process.Store_Num 
FROM FranchiseData
INNER JOIN AccountCancellation_Process
on FranchiseData.StoreNo = AccountCancellation_Process.Store_Num

select count(*) from AccountCancellation_Process where Store_Num = '1234' 
select count(*) from AccountCancellation_Process where Store_Num = '1234' and Progress is not null
SELECT DISTINCT Franchise.FranchiseName, Franchise.Initials, Franchise.StoreNo, acp.Store_Num, total_count.Total_Count, progress_count.Progress_Count
FROM FranchiseData
     INNER JOIN AccountCancellation_Process AS acp ON (FranchiseData.StoreNo = acp.Store_Num)
     INNER JOIN (SELECT Store_Num, COUNT(*) AS Total_Count FROM AccountCancellation_Process WHERE Store_Num = acp.Store_Num) AS total_count ON (acp.Store_Num = total_count.Store_Num)
     INNER JOIN (SELECT Store_Num, COUNT(*) AS Progress_Count FROM AccountCancellation_Process WHERE Store_Num = acp.Store_Num AND Progress IS NOT NULL) AS progress_count ON (acp.Store_Num = progress_count.Store_Num)