select     COUNT(distinct  Name) from Door  group by ID,Name

 select     DoorID,  DoorName ,COUNT(distinct DoorName) from Door group by ID,Name


distinct  会有损耗性能问题,不过有个前提是数据量够大,100万级别以上


group by  好些

 

                                       
                                       






本文转载:CSDN博客