select dm,count(*) as nmu
from 表
group by dm

解决方案 »

  1.   

    ----------------------------------------------------------------
    -- Author  :DBA_Huangzj(發糞塗牆)
    -- Date    :2013-12-20 14:59:05
    -- Version:
    --      Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 
    -- Dec 28 2012 20:23:12 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
    --
    ----------------------------------------------------------------
    --> 测试数据:[huang]
    if object_id('[huang]') is not null drop table [huang]
    go 
    create table [huang]([id] int,[dm] int)
    insert [huang]
    select 5945,320324 union all
    select 5921,320382 union all
    select 5953,320721 union all
    select 5808,320721 union all
    select 5809,320721 union all
    select 5810,320724 union all
    select 5811,320724 union all
    select 5814,320724
    --------------开始查询--------------------------select dm,COUNT(dm)[不同次数]
     from [huang]
     GROUP BY dm
    ----------------结果----------------------------
    /* 
    dm          不同次数
    ----------- -----------
    320324      1
    320382      1
    320721      3
    320724      3
    */