A表有两个字段a、b,a字段有重复的,现在要做个全表查询,碰到a重复的记录就只取其中一条,要求只能用查询语句,
有人会么?不能delete 或建临时表

解决方案 »

  1.   

    随便取一条?
    select * from
    (select a.*,row_number()over(partition by a order by rownum)rn
      from a)
    where rn=1
      

  2.   

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

  3.   

    ------测试数据如下
    --a---------------b----
      2 bbb
      1 aaa
      2 ddd
      2 cccselect * from 
    (select a.*,row_number()over(partition by a.col order by rownum)rn 
      from a) 
    where rn=1-----查询出来数据如下:
    --a----------b--
    1 aaa
    2 ccc
      

  4.   

    ------测试数据如下
    --a--b--
      2 bbb
      1 aaa
      2 ddd
      2 cccselect * from 
    (select a.*,row_number()over(partition by a.col order by rownum)rn 
      from a) 
    where rn=1-----查询出来数据如下:
    --a--b--
    1 aaa
    2 ccc
      

  5.   

    select * from debug a 
    where rowid = (select max(rowid) from debug b where a.id=b.id)
      

  6.   

    这个debug是个什么意思
    没见过
      

  7.   

    select * from tab a
    where not exists( select 1 from tab b where a.a=b.a and a.rowid<b.rowid);
      

  8.   

    select * from 
    (select a.*,row_number()over(partition by a order by dbms_random.random) rn from a) 
    where rn = 1;