select distinct * from 表

解决方案 »

  1.   

    select distinct * from 表distinct 保证 查出来的字段的组合是唯一的
      

  2.   

    select distinct * from tablename
      

  3.   

    select distinct * from 表
      

  4.   

    select distinct * from 表
      

  5.   

    select distinct * from 表我也是,来蹭点分!!
      

  6.   

    select distinct * into #T from 表delete  from 表insert into 表
    select * from #T
    drop table #T
      

  7.   

    呵呵,那我也别客气啦如果你想要去掉表中所有字段都重复的数据那就这样写吧:select distinct * from table1如果你只想去掉表中某字段出现的重复数据,那就是这样写啦select distinct 某字段  from table1
      

  8.   

    select distinct * from TABLE
      

  9.   

    这样不行啊,另外还有两个主键
    devid     cityid  roadnum     metername   meapointid
      7555      20      1          脉冲表(5)     5
      7555      20      2          脉冲表(5)     5
      7555      20      3          脉冲表(4)     4
      7555      20      4          脉冲表(3)     3
      7666      20      1          脉冲表(6)     6
      7666      20      2          脉冲表(6)     6
      7666      20      3          脉冲表(5)     5
      7999      20      1          脉冲表(7)     7
      7999      20      2          脉冲表(5)     5
      7888      20      1          脉冲表(8)     8其中devid,cityid,roadnum构成主键
      

  10.   

    --其中devid,cityid,roadnum构成主键
    如果这样的话,主键没有重复,不够成重复记录
    --如果要从后面取一条记录!那主键的值怎么确定??
      

  11.   

    --是不是楼主要这样的结果,除去主键,如有重复,取一条,给你一个例子
    --如果除主键有其它记录重复,则取其中一条,主键组合roadnum假设取最大值,如下:--创建测试环境
    declare @t table(devid varchar(4),cityid int ,roadnum int,metername varchar(10),meapointid int)
    insert into @t select '7555',20,1,'脉冲表(5)',5
    union all select '7555',20,2,'脉冲表(5)',5
    union all select '7555',20,3,'脉冲表(4)',4
    union all select '7555',20,4,'脉冲表(3)',3
    union all select '7666',20,1,'脉冲表(6)',6
    union all select '7666',20,2,'脉冲表(6)',6
    union all select '7666',20,3,'脉冲表(5)',5
    union all select '7999',20,1,'脉冲表(7)',7
    union all select '7999',20,2,'脉冲表(5)',5
    union all select '7888',20,1,'脉冲表(8)',8
    --查询
    select devid=min(devid),
    cityid=min(cityid),
    roadnum=(select max(roadnum) from @t where metername=a.metername and meapointid=a.meapointid and devid=a.devid),
    metername,
    meapointid
     from @t a
    group by devid,metername,meapointid
    order by devid
    --结果devid cityid      roadnum     metername  meapointid  
    ----- ----------- ----------- ---------- ----------- 
    7555  20          2           脉冲表(5)     5
    7555  20          3           脉冲表(4)     4
    7555  20          4           脉冲表(3)     3
    7666  20          2           脉冲表(6)     6
    7666  20          3           脉冲表(5)     5
    7888  20          1           脉冲表(8)     8
    7999  20          1           脉冲表(7)     7
    7999  20          2           脉冲表(5)     5(所影响的行数为 8 行)--不知道是不是要这个结果!
      

  12.   

    devid    metername  meapointid  
    -----  ---------- ----------- 
    7555      脉冲表(5)     5
    7555      脉冲表(4)     4
    7555      脉冲表(3)     3
    7666      脉冲表(6)     6
    7666      脉冲表(5)     5
    7888      脉冲表(8)     8
    7999      脉冲表(7)     7
    7999      脉冲表(5)     5我只需要这三列,还有就是贴子发错地方了,环境是ORACLE啊
      

  13.   

    zlp321002(想在北京找份工作!) ,是你说的意思,能帮我解决吗,我是通过查询两个表生成一个视图,视图内容就是上面的
      

  14.   

    --ORACLE 很久没用了!但这个是标准的SQL,Oracle应该支持!我没有用到SQL里的其它系统函数!
    --创建测试环境
    declare @t table(devid varchar(4),cityid int ,roadnum int,metername varchar(10),meapointid int)
    insert into @t select '7555',20,1,'脉冲表(5)',5
    union all select '7555',20,2,'脉冲表(5)',5
    union all select '7555',20,3,'脉冲表(4)',4
    union all select '7555',20,4,'脉冲表(3)',3
    union all select '7666',20,1,'脉冲表(6)',6
    union all select '7666',20,2,'脉冲表(6)',6
    union all select '7666',20,3,'脉冲表(5)',5
    union all select '7999',20,1,'脉冲表(7)',7
    union all select '7999',20,2,'脉冲表(5)',5
    union all select '7888',20,1,'脉冲表(8)',8
    --查询
    select devid=min(devid),
    metername,
    meapointid
     from @t a
    group by devid,metername,meapointid
    order by devid,meapointid desc
    --结果
    devid metername  meapointid  
    ----- ---------- ----------- 
    7555  脉冲表(5)     5
    7555  脉冲表(4)     4
    7555  脉冲表(3)     3
    7666  脉冲表(6)     6
    7666  脉冲表(5)     5
    7888  脉冲表(8)     8
    7999  脉冲表(7)     7
    7999  脉冲表(5)     5(所影响的行数为 8 行)
      

  15.   

    select distinct devid   metername   meapointid  from tablename
      

  16.   

    delete from tablename t1 where where t1.rowid !=
    (select max(rowid) from tablename t2
    where t1.id=t2.id and t1.name=t2.name)
      

  17.   

    select devid,cityid,roadnum from tablename
    group by devid,cityid,roadnum
      

  18.   

    select devid,metername,meapointid from 表unionselect devid,metername,meapointid from 表
      

  19.   

    select distinct devid,metername ,meapointid  from tablename
    这样不行,楼主我请你吃饭。