有表A是用户信息,字段为:
user_name varchar2(32)
con_mobile varchar2(12)
B是缴费记录表,字段为:
user_name varchar2(32)    --此字段为外键,与A表连接
pay_id integer
pay_date date
charge integer现要求查询最后缴费日期在某天之前的用户名字及联系方式,该怎么写?

解决方案 »

  1.   

    select a.user_name ,a.con_mobile from a,
        (select user_name ,max(pay_date) as  m_date from b group by user_name) b
    where a.user_name = b.user_name
     and to_char(m_date,'yyyy/mm/dd')  < to_char(sysdate,'yyyy/mm/dd')
      

  2.   

    select * from 
    (select user_name,max(pay_date) max_date from b group by username) c,a d where d.user_name=c.user_name and c.max_date<指定日期
      

  3.   

    select a.* 
      from a, 
        (select user_name ,max(pay_date) as  maxdate from b group by user_name) b 
    where a.user_name = b.user_name 
     and maxdate  < to_date(指定日期,'yyyy-mm-dd')
      

  4.   

    谢谢各位,第一个回复给最高分,另外Robin_Ares的语句也最严谨。