select * 
from 表 t
where 日期字段 in(select distinct top 2 日期字段 
                      from 表 
                          where 客户=t.客户 
                               order by 日期字段 desc)
order by 客户

解决方案 »

  1.   

    select * 
    from 表 t
    where 日期字段 in(select  top 2 日期字段 
                          from 表 
                              where 客户=t.客户 
                                   order by 日期字段 desc)
    order by 客户
      

  2.   

    select * 
    from 表 t
    where  (select count(distinct 时间字段) from 表 where 客户=t.客户 and  时间字段 >t.时间字段)<2 group by 客户
      

  3.   


    上面的表t是什么?
    select id,cuscode,cusprice,pricedate from Price 
    查询出来的结果cuscode cusprice pricedate          id
    14 458.00 2005-07-01 00:00:00.000 56
    14 630.00 2005-07-01 00:00:00.000 61
    15 510.00 2005-07-01 00:00:00.000 62
    15 707.00 2005-07-01 00:00:00.000 63
    15 563.00 2005-07-01 00:00:00.000 65
    17 720.00 2005-07-01 00:00:00.000 66
    10 674.00 2005-07-01 00:00:00.000 70
    10 650.00 2005-07-01 00:00:00.000 71
    10 650.00 2005-07-01 00:00:00.000 75
    21 318.34 2005-07-01 00:00:00.000 76
    24 517.00 2005-07-01 00:00:00.000 81
    25 600.00 2005-07-01 00:00:00.000 82
    26 700.00 2005-07-01 00:00:00.000 85
    27 540.00 2005-07-01 00:00:00.000 86
    27 720.00 2005-07-01 00:00:00.000 87
    33 642.00 2005-07-01 00:00:00.000 91
    34 569.00 2005-07-01 00:00:00.000 92
    35 626.97 2005-07-01 00:00:00.000 93
    35 620.00 2005-07-01 00:00:00.000 94
    35 660.00 2005-07-01 00:00:00.000 95
    35 450.00 2005-07-01 00:00:00.000 96
    36 664.00 2005-07-01 00:00:00.000 97
    36 760.00 2005-07-01 00:00:00.000 98
    37 590.00 2005-07-01 00:00:00.000 99
    38 340.00 2005-07-01 00:00:00.000 100
    38 361.90 2005-07-01 00:00:00.000 101
    38 380.00 2005-07-01 00:00:00.000 102
    38 422.50 2005-07-01 00:00:00.000 103
    38 253.00 2005-07-01 00:00:00.000 104
    39 345.00 2005-07-01 00:00:00.000 105
    39 390.00 2005-07-01 00:00:00.000 106
    40 656.00 2005-07-01 00:00:00.000 107
    40 660.00 2005-07-01 00:00:00.000 108
    40 660.00 2005-07-01 00:00:00.000 110
    41 620.00 2005-07-01 00:00:00.000 111
    41 760.00 2005-07-01 00:00:00.000 112
    41 660.00 2005-07-01 00:00:00.000 113
    42 370.00 2005-07-01 00:00:00.000 114
    42 433.00 2005-07-01 00:00:00.000 115
    42 433.00 2005-07-01 00:00:00.000 116
    43 430.00 2005-07-01 00:00:00.000 117
    45 450.00 2005-07-01 00:00:00.000 121
    46 740.00 2005-07-01 00:00:00.000 126
    46 740.00 2005-07-01 00:00:00.000 127
    47 580.00 2005-07-01 00:00:00.000 128
    47 490.00 2005-07-01 00:00:00.000 129
    48 440.00 2005-07-01 00:00:00.000 130
    49 594.00 2005-07-01 00:00:00.000 131
    49 578.00 2005-07-01 00:00:00.000 132
      

  4.   

    select top 2 from 表名 a,表名 b
    where a.客户名=b.客户名 
    group by 客户名
    orderby 日期字段 
    我认为是这样。。.....
      

  5.   

    --try (T为表别名)select * 
    from Price  t
    where pricedate  in(select distinct top 2 pricedate  
                          from Price
                              where cuscode=t.cuscode 
                                   order by pricedate  desc)
    order by cuscode
      

  6.   

    where 客户=t.客户
    是什么意思?
    难道要列举所有的客户?
      

  7.   

    zlp321002(人生没有理想,那和咸鱼还有什么两样)  大侠的OK了,,
    感谢感谢~~