通过
select dw_xh,dh,ch_dwname,xxt_qydh.xh 
       from xxt_qydh,xxt_cxzb 
       where dw_xh=xxt_cxzb.xh and dh='118318' 我查出来的记录是下面这样的
         A DH                           XH
---------- -------------------- ----------
      9447 118318                     6001
      9447 118318                    31116
      9447 118318                    31118
      9447 118318                    31120
      9447 118318                    31138
      9449 118318                     6002
      9449 118318                    31127
      9449 118318                    31130
      9449 118318                    31132
      9453 118318                     6004
      9453 118318                    31113
      9453 118318                    31122
      9453 118318                    31124
------------------------------------------
但是我实际相要的是下面的样子,xh的不是很重要,但是必须有
      9447 118318                     6001
      9449 118318                     6002
      9453 118318                     6004有没有用一句话解决的办法么?

解决方案 »

  1.   

    select A, DH, XH from 
    (select A, DH, XH, row_number() over(partition by A order by xh)rnum
    from (select A, DH, XH from tab_name ))
    where rnum = 1;
    不清楚楼主的SQL语句怎么能得到楼主列出来的记录:
    select dw_xh,dh,ch_dwname,xxt_qydh.xh  ---4个字段
    from xxt_qydh,xxt_cxzb
    where dw_xh=xxt_cxzb.xh and dh='118318'
    我查出来的记录是下面这样的
    A DH XH  --3个字段???
    ---------- -------------------- ----------
      

  2.   

    select dw_xh,dh,ch_dwname,max(xxt_qydh.xh)
           from xxt_qydh,xxt_cxzb 
           where dw_xh=xxt_cxzb.xh and dh='118318' 
    group by dw_xh,dh,ch_dwname