寻求一些帮助,我基本上只需要从以下查询中返回一个计数:
USE MediaProcessingQueue;
SELECT DISTINCT dbo.MessageQueue.messageId,dbo.MessageQueue.state,dbo.MessageQueue.wsaMessageId,dbo.MessageQueue.refId,dbo.StatusUpdate.messageId
FROM dbo.MessageQueue
INNER JOIN dbo.StatusUpdate
ON dbo.MessageQueue.messageId=dbo.StatusUpdate.messageId
WHERE dbo.MessageQueue.state ='1' AND dbo.StatusUpdate.percentComplete > 12
任何帮助都非常感激。
答案 0 :(得分:0)
将Count
放在DISTINCT
列附近。
Use MediaProcessingQueue
GO
select Count(DISTINCT dbo.MessageQueue.messageId,dbo.MessageQueue.state,dbo.MessageQueue.wsaMessageId,dbo.MessageQueue.refId,dbo.StatusUpdate.messageId)
FROM dbo.MessageQueue
INNER JOIN dbo.StatusUpdate
ON dbo.MessageQueue.messageId=dbo.StatusUpdate.messageId
WHERE dbo.MessageQueue.state ='1' AND dbo.StatusUpdate.percentComplete > 12
答案 1 :(得分:0)
SELECT Count(*)
FROM (
<insert your existing query here>
) As a_subquery
答案 2 :(得分:0)
如果你想获得只计数使用这个
Select Count(DISTINCT dbo.MessageQueue.messageId,dbo.MessageQueue.state,dbo.MessageQueue.wsaMessageId,dbo.MessageQueue.refId,dbo.StatusUpdate.messageId)
如果您想获得计数以及查询输出,请使用此
select @@ROWCOUNT
选择查询后的下一行。
答案 3 :(得分:0)
你也可以这样做:
带有Count(*)
的 Sum(1)
或Group By
USE MediaProcessingQueue;
SELECT Sum(1)
FROM dbo.MessageQueue
INNER JOIN dbo.StatusUpdate
ON dbo.MessageQueue.messageId=dbo.StatusUpdate.messageId
WHERE dbo.MessageQueue.state ='1' AND dbo.StatusUpdate.percentComplete > 12
GROUP BY dbo.MessageQueue.messageId, dbo.MessageQueue.state, dbo.MessageQueue.wsaMessageId, dbo.MessageQueue.refId, dbo.StatusUpdate.messageId