1

我正在Sum()尝试Status. Status = 'operational'我无法弄清楚如何总结实际的“操作”一词。

我尝试了以下语句的多种不同变体(我发布的是最基本的形式),但我收到错误:data type varchar is invalid for sum operator.

有人可以帮忙吗?

SELECT SUM(status) As 'TotalOperationalSTIDevices'
FROM netinfo_device_details
WHERE LoopBackAddress LIKE '10.12%' AND Status = 'Operational'
4

2 回答 2

1

您需要使用 COUNT:

SELECT COUNT(*) As TotalOperationalSTIDevices 
FROM netinfo_device_details 
WHERE LoopBackAddress LIKE '10.12%' AND Status = 'Operational';

SUM 聚合函数实际上是对一组数字进行求和。COUNT 只计算行数。由于该行的实际内容不相关,因此您可以根据需要使用 COUNT(*) 而不是 COUNT(status)。

于 2013-11-13T17:58:34.080 回答
1

尝试

Select COUNT(*) As 'TotalOperationalSTIDevices' from netinfo_device_details where LoopBackAddress Like '10.12%' and Status = 'Operational'
于 2013-11-13T17:59:09.067 回答