假设你用的是SQL SERVER
1.select distinct field into newtable from oldtable
drop table oldtable2.use dts
1.select distinct field into newtable from oldtable
drop table oldtable2.use dts
解决方案 »
- 如何验证代理地址是否可用 delphi
- 关于idTCPServer和idTCPClient(100分送上)
- 在按下鼠标左键拖拉Treeview里的节点时,如何让Treeview的滚动条跟着鼠标拖动的方向一起滚动?
- 密码登陆的问题,请指教
- 我这样写的自动登录身份验证错在哪里了?
- 关于将access 导入Sql server 2000的问题
- 怎样根据edit控件里的一个坐标获得edit句炳
- 各位大哥:符号^是什么意思?
- 关于DBGrid的操作————急!!!
- 请问在Delphi中怎么调用动态生成的form?
- 这段Delphi英文帮助是什么意思?(三天结帖)
- 如何在BDE的Query中使用Sybase的数据类型转换函数
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;
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;
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)
1、我现在就是不想另外加新表,如何在同一个表中操作?
2、能不能详细一点?
谢谢~~
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;