本帖最后由 wingson_shen 于 2013-11-21 09:34:39 编辑

解决方案 »

  1.   

    SELECT T1.*, T2.COUNT
      FROM T_PRODUCT T1,
           (SELECT T1.PID, T1.COUNT
              FROM T_RECORD T1,
                   (SELECT MAX(T.ID) ID, T.PID FROM T_RECORD T GROUP BY T.PID) T2
             WHERE T1.ID = T2.ID
               AND T1.PID = T2.PID) T2
     WHERE T1.ID = T2.PID(+)
      

  2.   

    with t_product as
     (
      
      select 1 id, 'p_name_1' name
        from dual
      union
      select 2 id, 'p_name_2' name
        from dual
      union
      select 3 id, 'p_name_3' name from dual),
    t_record as
     (select 1 id, 1 pid, 5 count
        from dual
      union
      select 2 id, 1 pid, 6 count
        from dual
      union
      select 3 id, 2 pid, 7 count from dual)select a.id, a.name, b.count
      from t_product a,
           (select pid, max(count) KEEP(DENSE_RANK FIRST ORDER BY id desc) count
              from t_record
             group by pid) b
     where a.id = b.pid(+)
      

  3.   

    select t1.id, t1.name, max(t2.count) max_count
      from t_product t1
      left join t_record t2
        on t1.id = t2.pid
     group by t1.id, t1.name