delete a from 表 a
where exists(
select 1 from 表 where id=a.id and 
time <>(select min(time) from 表 where id=a.id )
and 
time <>(select max(time) from 表 where id=a.id )
)

解决方案 »

  1.   

    select 
    card_id ,
    convert(varchar(10),sign_time,120)  as 日期
    min(sign_time) as 当天最早,
    max(sign_time) as 当天最晚
    from 
    timerecords
    group by card_id,convert(varchar(10),sign_time,120) 
      

  2.   


    select * from timerecords a
    where not exists(select 1 from timerecords b where a.id=b.id and a.time>b.time )
    union all
    select * from timerecords a
    where not exists(select 1 from timerecords b where a.id=b.id and a.time<b.time )
      

  3.   

    select * from timerecords a
    where not exists(select 1 from timerecords  where card_id=a.card_id and datediff
    (dd,sign_time,a.sign_time)=0 and sign_time>a.sign_time)
    union all
    select * from timerecords a
    where not exists(select 1 from timerecords  where card_id=a.card_id and datediff
    (dd,sign_time,a.sign_time)=0 and sign_time<a.sign_time)
      

  4.   

    --显示为两条记录select 
    *
    from 
    timerecords a
    where
    sign_time=(select max(sign_time) from timerecords where card_id=a.card_id and datediff(d,sign_time,a.sign_time )=0)
    or
    sign_time=(select min(sign_time) from timerecords where card_id=a.card_id and datediff(d,sign_time,a.sign_time )=0)
      

  5.   

    min(time),max(time)是这意思么……看你的意思是所有的记录都在一张表内我想可以做个while循环~循环找每天的min(time),max(time)
      

  6.   

    数据库表为timerecords,里面纪录了每天的员工刷卡的卡号:card_id和时间:sign_time,每个卡号都有多条纪录,现在需要根据每天的刷卡时间来纪录考勤情况,也就是只留下每天每个员工刷卡最早的一次和最晚的一次刷卡纪录,中间其他的纪录删除掉.请高手指教!!select card_id , min(sign_time) sign_time_min from timerecords group by card_id
    union all
    select card_id , max(sign_time) sign_time_max from timerecords group by card_id
      

  7.   

    --如果只有card_id , sign_time两个字段.
    select card_id , min(sign_time) sign_time_min from timerecords group by card_id
    union all
    select card_id , max(sign_time) sign_time_max from timerecords group by card_id--如果不止card_id , sign_time两个字段.
    select t.* from timerecords t where sign_time = (select min(sign_time) from timerecords where card_id = t.card_id)
    union all
    select t.* from timerecords t where sign_time = (select max(sign_time) from timerecords where card_id = t.card_id)