[英]SQL Server: query results from another query?
我下面有一个查询,该查询返回要尝试对Name
计数的124行并返回值124。是否有一种简单的方法可以查询此查询的结果或仅添加另一列?
declare @Logins varchar(max)
Select
Name, UserName, CreationDate, TimeDataRetrieval,
TimeProcessing, TimeRendering, ByteCount, [RowCount],
path, TimeEnd, Format,
COUNT(*) over(partition by format) AS FormatCnt,
COUNT(NAME) AS HUH
From
(SELECT
cat.Name,
SUBSTRING(ex.UserName, CHARINDEX('\', ex.UserName) + 1,
LEN(ex.UserName) - CHARINDEX('\', ex.UserName)) AS UserName,
cat.CreationDate, ex.TimeDataRetrieval, ex.TimeProcessing,
ex.TimeRendering, ex.ByteCount, ex.[RowCount],
cat.path, ex.TimeEnd, ex.Format
FROM
ExecutionLog AS ex
INNER JOIN
Catalog AS cat ON ex.ReportID = cat.ItemID) AS ZZ
--WHERE UserName in (@Logins)
--and
WHERE UserName = 'user1'
AND (Path NOT LIKE '%Autodelivery%'
AND Path NOT LIKE '%admin%'
AND Path NOT LIKE '%qa%'
AND path NOT LIKE '%test%')
GROUP BY
ZZ.UserName, ZZ.Name, ZZ.ByteCount, ZZ.CreationDate, ZZ.Format, ZZ.Path,
ZZ.[RowCount], ZZ.TimeDataRetrieval, ZZ.TimeEnd, ZZ.TimeProcessing,
ZZ.TimeRendering
ORDER BY
Name, TimeEnd DESC
在您的代码中,您可以使用这种格式...
declare @Logins varchar(max)
SELECT COUNT(a.name)
FROM (
Select Name, UserName, CreationDate, TimeDataRetrieval, TimeProcessing,TimeRendering, ByteCount, [RowCount], path, TimeEnd, Format, COUNT(*) over(partition by format) AS FormatCnt, COUNT(NAME)AS HUH
From
(
SELECT cat.Name, SUBSTRING(ex.UserName, CHARINDEX('\', ex.UserName) + 1, LEN(ex.UserName) - CHARINDEX('\', ex.UserName)) AS UserName,
cat.CreationDate, ex.TimeDataRetrieval, ex.TimeProcessing, ex.TimeRendering, ex.ByteCount, ex.[RowCount], cat.path, ex.TimeEnd, ex.Format
FROM ExecutionLog AS ex INNER JOIN
Catalog AS cat ON ex.ReportID = cat.ItemID
) AS ZZ
--WHERE UserName in (@Logins)
--and
WHERE UserName = 'user1'
and
(Path not like '%Autodelivery%'
and Path not like '%admin%'
and Path not like '%qa%'
and path not like '%test%')
GROUP BY ZZ.UserName, ZZ.Name, ZZ.ByteCount, ZZ.CreationDate, ZZ.Format, ZZ.Path, ZZ.[RowCount], ZZ.TimeDataRetrieval, ZZ.TimeEnd, ZZ.TimeProcessing, ZZ.TimeRendering
--order by Name, TimeEnd desc
) a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.