楼主是这个意思吧。Select * from test A 
Where Not Exists (Select 1 from test Where id=A.id And datatime<A.datatime)

解决方案 »

  1.   

    Or 
    Select A.* from test A 
    Inner Join (Select id,Min(datatime) As datatime from test Group By id) B
    On A.id=B.id And A.datatime=B.datatime
    Order By A.id这种方法效率更高
      

  2.   

    一天到晚游泳的鱼,你的两个方法好像都不行呀,我的数据有很多,除了我列出来的14时的数据外,y一年365天,一天24小时,每一个小时都有数据,而且每一个id可能不只一个数据,我列出来的数据是我的一个查询出来的结果,我把我的sql语句给你看看,请你帮我修改一下,谢谢!select id,datatime,data
    from test
    where datepart(hh,datatime)=14 and datediff(day,datatime,getdate())=0 
    order by id asc,datatime asc
    这个数据可以查询今天14时的数据,但是查询的结果id=0007的出现了4个,我只要一个,也就是14:00时的,也就是结果应该是这样的才行:0001,2005-06-06 14:00:00.000,239.85
    0002,2005-06-06 14:00:00.000,172.83
    0003,2005-06-06 14:00:00.000,60.52
    0004,2005-06-06 14:00:00.000,159.78
    0005,2005-06-06 14:00:00.000,142.67
    0006,2005-06-06 14:00:00.000,89.28
    0007,2005-06-06 14:00:00.000,82.07
    0008,2005-06-06 14:00:00.000,189.91
    0009,2005-06-06 14:00:00.000,76.28
    0010,2005-06-06 14:00:00.000,79.03
    0011,2005-06-06 14:00:00.000,83.08
    0012,2005-06-06 14:00:00.000,52.13
    0015,2005-06-06 14:00:00.000,78.02
    请各位帮我解答一下,谢谢!
      

  3.   

    你是要'2005-06-06 14:00:00.000'这个时候的数据是吧。那直接这样不就可以吗??select id,datatime,data
    from test
    where datediff(ss,datatime,'2005-06-06 14:00:00.000')=0 
    order by id asc,datatime asc
      

  4.   

    select * from test where  datepart(mi,datatime)=0  and datepart(hh,datatime)=14 
    and id=7
      

  5.   

    select * from test where  datepart(mi,datatime)=0  and
     datepart(hh,datatime)=14 and id=7
      

  6.   

    猜测:按照楼主的意思,估计 id和datatime 共同作为复合键