简体   繁体   English

如何根据Sql server中3列的3个不同值查找列数?

[英]How to find count of column, based on 3 distinct values of 3 columns in Sql server?

我的表看起来像这样,它有200行

I need to count the no.of rooms in eachbuilding, each floor and in each zone..(like this in below picture) 我需要计算每个建筑物,每个楼层和每个区域的房间数量..(如下图所示) 在此输入图像描述

I have tried using distinct and group by, but I am not getting required result. 我尝试过使用distinct和group by,但是我没有得到必需的结果。

You have not supplied the actual SQL you have trued, but something like this should work (obviously with the correct field / table names) 你没有提供你已经修改的实际SQL,但是这样的东西应该可以工作(显然有正确的字段/表名)

SELECT BuildingNo, Floor, Zone, COUNT(Rooms) AS NoOfRooms
FROM myTable
GROUP BY BuildingNo, Floor, Zone
ORDER BY BuildingNo, Floor, Zone

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM