In the below query I have a table name indent I have different indentid count for different locations. But it shows the indentid count for last location. I want to display all location indentID count.
在下面的查询中我有一个表名缩进我有不同位置的不同的indentid计数。但它显示了最后一个位置的独立计数。我想显示所有位置缩进计数。
I want to display count like this
我想显示这样的计数
15
20
1
- 15 - for first location
- 20 - second location
- 1 - third Location
15 - 第一个位置
20秒的位置
1 - 位置
Code:
DECLARE @LocationID int
SELECT @LocationID = LocationID FROM Locations
SELECT COUNT(IndentID) AS OpenedIndent
FROM Indent I
WHERE POStatusID IN (1,2)
AND I.LocationID = @LocationID
1 个解决方案
#1
1
You need to use group by as below
您需要使用group by,如下所示
SELECT COUNT(IndentID) AS OpenedIndent
FROM Indent I
WHERE POStatusID IN (1,2)
GROUP BY I.LocationID
#1
1
You need to use group by as below
您需要使用group by,如下所示
SELECT COUNT(IndentID) AS OpenedIndent
FROM Indent I
WHERE POStatusID IN (1,2)
GROUP BY I.LocationID