select rownum as rn,a.CALLID,a.CALLERNO,a.CALLEENO,to_char(a.CALLBEGIN,'yyyy-mm-dd hh24:mi:ss') beginTime,to_char(a.CALLEND,'yyyy-mm-dd hh24:mi:ss') 
endTime,a.RELEASECAUSE,a.DISTINCTION,a.CALLOUTCOUNT,a.CALLOUTSUCCESS, b.NAME
            from t_agent_latel_releasebillog a,customerinfo b where a.callerno=b.userphone  order by begintime因为是联表查询,想查询出所有b.name的不重复记录,并且按照begintime降序排列

解决方案 »

  1.   

    distnct 加在select 后试试,升序降序网上查下很多
      

  2.   

    不对,应该先把b表的Name相同项去除再连表可能就行了
      

  3.   

    好乱啊 用子查询是不是能好点  去掉重复的话 就像楼上说的 在select 后面加 distinct排序用的话在后面加 order by begintime;
      

  4.   


    distinct :如果只是 select b.name from **  有用,这里来说 其实搜索出的每个行都不是一样的,因为还有其他列是不一样的。感觉你这个需求有点问题,你的意思是同一个 b.name有多条不同的记录,所以要b.name不重复;那同一个b.name下的多条记录要哪条呢?随机选一条么?order by begintime desc 就是降序
      

  5.   


    select t2.* from (
    select t1.*,row_number over()over (partition by t1.NAME order by t1.begintime) rn from(
    select rownum as rn,a.CALLID,a.CALLERNO,a.CALLEENO,
    to_char(a.CALLBEGIN,'yyyy-mm-dd hh24:mi:ss') beginTime,
    to_char(a.CALLEND,'yyyy-mm-dd hh24:mi:ss'endTime,a.RELEASECAUSE,
    a.DISTINCTION,a.CALLOUTCOUNT,a.CALLOUTSUCCESS, b.NAME
    from t_agent_latel_releasebillog a,customerinfo b 
    where a.callerno=b.userphone order by begintime
    )t1
    )t2 where rn=1
      

  6.   

    忘排序了
    最后面再加个order by begintime desc
      

  7.   

    distinct只能放句首,而且和我的需求不符合,后来找了个高人解决了
    select * from (
    select rownum as rn,a.CALLID,a.CALLERNO,a.CALLEENO,to_char(a.CALLBEGIN,'yyyy-mm-dd hh24:mi:ss') beginTime,
    to_char(a.CALLEND,'yyyy-mm-dd hh24:mi:ss') 
    endTime,a.RELEASECAUSE,a.DISTINCTION,a.CALLOUTCOUNT,a.CALLOUTSUCCESS, b.NAME,row_number() over(partition by b.name order by a.CALLBEGIN desc) cnt
    from t_agent_latel_releasebillog a,customerinfo b 
    where a.callerno=b.userphone  
    )
    where cnt = 1
    表示看不太懂
      

  8.   

    row_number() over(partition by b.name order by a.CALLBEGIN desc) cnt
    按name 分区(group by ) 时间倒叙,产生一个序列号。