Ddate               ZdCode         
 2011-01-25            A
 2011-01-26            B
 2011-01-26            A
 2011-01-26            A
 2011-01-27            B
 2011-01-27            C
 2011-01-28            B
 2011-01-28            B
 2011-01-29            C
 2011-01-30            C
 2011-02-01            A
我要通过分组得出以下结果:
A
B
A
B
C
B
C
A

解决方案 »

  1.   

    select ZdCode from tb group by Ddate
      

  2.   

     declare @tb table (id int identity(1,1),ddate datetime, zdcode varchar(10))
     
     insert @tb
     values
     ('2011-01-25','A'),
     ('2011-01-26','B'),
     ('2011-01-26','A'),
     ('2011-01-26','A'),
     ('2011-01-27','B'),
     ('2011-01-27','C'),
     ('2011-01-28','B'),
     ('2011-01-28','B'),
     ('2011-01-29','C'),
     ('2011-01-30','C'),
     ('2011-02-01','A')
       
     select  * from @tb a
     where not exists(select 1 from @tb b where zdcode = a.zdcode and id = a.id -1)
     
      

  3.   


    ddate zdcode seqNo worktime2011-03-14 00:00:00 P1103049CC 80 2011-03-14 08:18:46.740 306 1060
    2011-03-15 00:00:00 P1103049CC 80 2011-03-15 08:16:00.697 306 1070
    2011-03-16 00:00:00 P1103049CC 80 2011-03-16 08:16:34.643 306 987
    2011-03-17 00:00:00 P1103049CC 80 2011-03-17 08:17:15.053 306 1061
    2011-03-18 00:00:00 P1103049CC 80 2011-03-18 08:16:53.897 306 1097
    2011-03-19 00:00:00 P1103049CC 80 2011-03-19 08:20:24.517 306 435
    2011-03-19 00:00:00 P1103049CD 80 2011-03-19 11:46:21.593 306 576
    2011-03-21 00:00:00 P1103049CD 80 2011-03-21 08:14:02.647 306 1006
    2011-03-22 00:00:00 P1103049CD 80 2011-03-22 08:20:59.353 306 729
    2011-03-22 00:00:00 P1103049EB 80 2011-03-22 16:02:37.037 306 364
    2011-03-23 00:00:00 P1103049GB 80 2011-03-23 09:42:25.020 306 594
    2011-03-23 00:00:00 P1103049EB 80 2011-03-23 08:20:29.640 306 143
    2011-03-23 00:00:00 P1103049GB 80 2011-03-23 18:17:03.517 308 217
    2011-03-24 00:00:00 P1103049EA 80 2011-03-24 11:54:22.317 308 262哈哈,我刚才没有写得具体,具体情况应是这样的
      

  4.   

    SeqNo出现连续的情况才进行分组,P1103049CC
    P1103049CC
    P1103049CD
    P1103049CD
    P1103049EB
    P1103049GB
    P1103049CD
    P1103049EA
      

  5.   


    select 
       SeqNo
    from
       (select ddate ,seqNo from tb group by ddate,seqNo)t