select id,min(contact_date) from table2
where  contact_date>'2002-12-16 00:00:00' and contact_date<'2002-12-18 00:00:00'
group by id

解决方案 »

  1.   

    如果要显示name的话:
    select a.id,b.name,min(a.contact_date) from table2 a join table1 b on a.id=b.id
    where  a.contact_date>'2002-12-16 00:00:00' and a.contact_date<'2002-12-18 00:00:00'
    group by a.id,b.name
      

  2.   

    select B.name, min(A.contact_date) from tab2 A
     left join tab1 B on A.id = B.id
     where A.contact_date>='2002-12-16 00:00:00'
       and A.contact_date<='2002-12-18 00:00:00'
     group by B.name