简体   繁体   中英

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.

You have not supplied the actual SQL you have trued, but something like this should work (obviously with the correct field / table names)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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