各位大侠好!表格如下:设备名称  出错代码     时间 
1           1       20130401
2           3       20130401
3           2       20130401
1           3       20130402
1           1       20130403
2           3       20130404
1           1       20130405
2           3       20130406
1           1       20130407
4           3       20130407
5           1       20130407
6           2       20130407
3           2       20130407结果:(任意top)
以下为这段时间内 top 3
设备名称  出错代码  出错数量
1           1         4
2           3         3
3           2         2单台设备一段时间内出错统计Top谢谢各位了!

解决方案 »

  1.   


    Create Table Device
    (
      设备名称 nvarchar(5),
      出错代码 nvarchar(5),
      时间  date
    )
    insert into Device
    select '1','1','20130401'
    union all
    select '2','3','20130401'
    union all
    select '3','2','20130401'
    union all
    select '1','3','20130401'
    union all
    select '1','1','20130401'
    union all
    select '2','3','20130401'
    union all
    select '1','1','20130401'
    union all
    select '2','3','20130401'
    union all
    select '1','1','20130401'
    union all
    select '4','3','20130401'
    union all
    select '5','1','20130401'
    union all
    select '6','2','20130401'
    union all
    select '3','2','20130401'select top 3 设备名称,出错代码,Count(设备名称) 出错数量 from Device
    group by 设备名称,出错代码
      

  2.   

    order by 出错数量 desc谢谢了!