在一次选择中返回两个 Count(*) 结果
我有一个存储过程,我希望它返回以下内容......
TotalItems | FailedItems
@totalItems | @failedItems
where --> @totalItems = `SELECT COUNT(*)
From dbo.OdsBuild AS P
where P.StartTime Between @StartDate and @EndDate
AND P.Official = 1`
where --> @failedItems = `SELECT COUNT(*)
From dbo.Items AS P
where p.StartTime Between @StartDate and @EndDate
AND P.Official = 1 AND ( P.Result = 7 OR P.Result = 8 OR P.Result = 14)`
I have a stored procedure and I want it to return the following...
TotalItems | FailedItems
@totalItems | @failedItems
where --> @totalItems = `SELECT COUNT(*)
From dbo.OdsBuild AS P
where P.StartTime Between @StartDate and @EndDate
AND P.Official = 1`
where --> @failedItems = `SELECT COUNT(*)
From dbo.Items AS P
where p.StartTime Between @StartDate and @EndDate
AND P.Official = 1 AND ( P.Result = 7 OR P.Result = 8 OR P.Result = 14)`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找的是 GROUP BY 和 HAVING
What you are looking for is GROUP BY and HAVING
子查询 SELECT COUNT
如果您已经将它们设置为变量,当然您不必重复 SELECT COUNT。
SELECT 语句可以独立存在,无需 FROM 子句。
Subquery the SELECT COUNTs
If you already had them set as variables, of course you don't have to repeat the SELECT COUNTs.
SELECT statements are allows to stand alone without FROM clauses.
您不能简单地在过程结束时选择这些变量吗?
Can't you simply select those variables at the end of your proc?