我有一个表td_cityflow_sheet_info 有sheet_id ,parent_id ,next_step_id 等字段
现在我要只通过parent_id进行分组得到next_step_id 最小的那一条的所有记录,记录中应包括所有的信息;
sheet_id 在库中是唯一的

解决方案 »

  1.   

    我写了一条SELECT MIN (t.sheet_id) sheet_id,MIN (to_number(t.next_step_id)) next_step_id,t.parent_id FROM td_cityflow_sheet_info t WHERE GROUP BY t.parent_id但得到的记录有些sheet_id不是对应那个next_step_id的记录
    急着解决!
    这个问题弄发了好久求教高手!在线等!
      

  2.   

    select min(a.sheet_id) sheet_id from td_cityflow_sheet_info a , (SELECT MIN (to_number(t.next_step_id)) next_step_id,t.parent_id FROM td_cityflow_sheet_info t WHERE SUBSTR (t.sheet_id, 0, 2) != 'CS' GROUP BY t.parent_id) b where a.parent_id = b.parent_id and a.next_step_id = b.next_step_id group by b.parent_id)
    我通过两个分组会影响效率吗?
    有没有更好的方法吗?
      

  3.   

    select *
    from 
    (
    select a.*,row_number() over(partition by parent_id order by next_step_id) rn
    from td_cityflow_sheet_info a
    )
    where rn=1
      

  4.   

    select * 
    from td_cityflow_sheet_info  
    where (parent_id,next_step_id ) in
          (select parent_id,min(next_step_id ) 
           from td_cityflow_sheet_info  
           group by parent_id)
      

  5.   

    analytic function row_number