假设你用的是SQL SERVER
1.select distinct field into newtable from oldtable
drop table oldtable2.use dts

解决方案 »

  1.   

    DELETE yourtable
     WHERE yourfield in (SELECT yourfield FROM yourtable GROUP BY yourfield HAVING COUNT(yourfield)>1)
    这样将会把有重复的记录都删除,好像简单的SQL语句不能达到你的要求,除非别的字段值不一样
    DELETE yourtable
     WHERE otherfield not in (SELECT MIN(otherfield) FROM yourtable GROUP BY yourfield HAVING COUNT(yourfield)>1)至于把表记录以文本形式导出相当简单
    var
      lfile : TEXTFILE;
      lvalue: string;
      loop  : Integer
    begin
      AssignFile(lfile,'c:\tmp.text');
      Rewrite(lfile);
      try
        while not yourquery.eof do
        begin
          lvalue := yourquery.Fields[0].AsString;
          for loop := 0 to yourquery.FieldCount-1 do
          begin
            lvalue := lvalue+yourquery.Fields[loop].AsString+'        ';
          end;
          Writeln(lfile,lvalue);
        end;
      finally
        CloseFile(lfile);
      end;
    end;
      

  2.   

    var
      lfile : TEXTFILE;
      lvalue: string;
      loop  : Integer
    begin
      AssignFile(lfile,'c:\tmp.text');
      Rewrite(lfile);
      try
        while not yourquery.eof do
        begin
          lvalue := yourquery.Fields[0].AsString;
          for loop := 0 to yourquery.FieldCount-1 do
          begin
            lvalue := lvalue+yourquery.Fields[loop].AsString+'        ';
          end;
          Writeln(lfile,lvalue);
          yourquery.Next;  //上面漏了一句
        end;
      finally
        CloseFile(lfile);
      end;
    end;
      

  3.   

    上面的SQL语句有点毛病
    DELETE yourtable
     WHERE otherfield not in (SELECT MIN(otherfield) FROM yourtable GROUP BY yourfield HAVING COUNT(yourfield)>1)
       AND yourfield not in (SELECT yourfield FROM yourtable GROUP BY yourfield HAVING COUNT(yourfield)>1)
      

  4.   

    to gmc007
    1、我现在就是不想另外加新表,如何在同一个表中操作?
    2、能不能详细一点?
    谢谢~~
      

  5.   

    太粗心,不好意思DELETE yourtable
     WHERE otherfield not in (SELECT MIN(otherfield) FROM yourtable GROUP BY yourfield HAVING COUNT(yourfield)>1)
       AND yourfield in (SELECT yourfield FROM yourtable GROUP BY yourfield HAVING COUNT(yourfield)>1)--------------------------------------------var
      lfile : TEXTFILE;
      lvalue: string;
      loop  : Integer
    begin
      AssignFile(lfile,'c:\tmp.text');
      Rewrite(lfile);
      try
        while not yourquery.eof do
        begin
          lvalue := yourquery.Fields[0].AsString;
          for loop := 1 to yourquery.FieldCount-1 do
          begin
            lvalue := lvalue+yourquery.Fields[loop].AsString+'        ';
          end;
          Writeln(lfile,lvalue);
          yourquery.Next;  //上面漏了一句
        end;
      finally
        CloseFile(lfile);
      end;
    end;