這是我的子查詢:
select
count(a.ProcessDate),
b.Market
from
[dbo].[FileProcessLog] a
left join
[dbo].[FileMaster] b on a.FileID = b.FileID
where
convert(date, a.ProcessDate) = convert(date, getdate()-2)
group by
b.Market
現在我想要結果表的行數,但是當我使用下面的查詢時出現錯誤:
select count(*)
from
(select count(a.ProcessDate), b.Market
from [dbo].[FileProcessLog] a
left join [dbo].[FileMaster] b on a.FileID = b.FileID
where convert(date, a.ProcessDate) = convert(date, getdate()-2)
group by b.Market)
我也嘗試過使用別名,但它根本不起作用。
請幫助尋找解決方案。
uj5u.com熱心網友回復:
with main as (
select
b.Market,
count(a.ProcessDate) as total
from [dbo].[FileProcessLog] a
LEFT JOIN [dbo].[FileMaster] b
ON a.FileID = b.FileID
where Convert(date, a.ProcessDate) = Convert(date, getdate()-2)
GROUP BY b.Market
) select count(*) as total_rows from main
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/525465.html
標籤:sqlsql服务器子查询
下一篇:替換特定的字串值
