举例说明:
com表:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
3 中南电脑 0125 ....
4 中南电脑 0125 ....
5 金鑫通迅 6587 ....
6 江南皮革 0265 ....
我要的结果记录集是:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
5 金鑫通迅 6587 ....
应该如何写sql语句
说明:数据库为Access数据,SQL语句必须能在Access里正确执行
17 个解决方案
#1
dim sql
sql="Select DISTINCT * From com"
Set objrs=Server.CreateObject("ADODB.RecordSet")
objrs.Open '打开数据库
sql="Select DISTINCT * From com"
Set objrs=Server.CreateObject("ADODB.RecordSet")
objrs.Open '打开数据库
#2
一个表中的frdm(法人代码)这个字段有重复,如何该删除重复的记录或者只显示不重复的记录...
举例说明:
com表:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
3 中南电脑 0125 ....
4 中南电脑 0125 ....
5 金鑫通迅 6587 ....
6 江南皮革 0265 ....
我要的结果记录集是:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
5 金鑫通迅 6587 ....
应该如何写sql语句
说明:数据库为Access数据,SQL语句必须能在Access里正确执行
引用-----------------------------
这不叫删除,用 distinct 筛选
举例说明:
com表:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
3 中南电脑 0125 ....
4 中南电脑 0125 ....
5 金鑫通迅 6587 ....
6 江南皮革 0265 ....
我要的结果记录集是:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
5 金鑫通迅 6587 ....
应该如何写sql语句
说明:数据库为Access数据,SQL语句必须能在Access里正确执行
引用-----------------------------
这不叫删除,用 distinct 筛选
#3
select distinct * from com into temp
delete from com
select * from temp into com
delete from com
select * from temp into com
#4
SELECT TOP 1000 * FROM FCXX_zF WHERE (((FCXX_zF.ID) In (SELECT ID FROM FCXX_zF GROUP BY ID HAVING COUNT(*) > 1))) ORDER BY FCXX_zF.ID DESC;
这是我以前解决类似问题的方法,参考一下
这是我以前解决类似问题的方法,参考一下
#5
我上面举的例子有点问题,并不是完全相同的记录,所以用distinct是不行的
举例说明:
com表:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 65
3 中南电脑 0125 .... 34
4 中南电脑 0125 .... 54
5 金鑫通迅 6587 .... 34
6 江南皮革 0265 .... 23
我要的结果记录集是:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 45
5 金鑫通迅 6587 .... 34
举例说明:
com表:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 65
3 中南电脑 0125 .... 34
4 中南电脑 0125 .... 54
5 金鑫通迅 6587 .... 34
6 江南皮革 0265 .... 23
我要的结果记录集是:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 45
5 金鑫通迅 6587 .... 34
#6
根据frdm这个字段,只要这个字段相同的就去掉相同的记录
#7
delect from com
where id not in
(
select max(id) from com group by frdm
)
where id not in
(
select max(id) from com group by frdm
)
#8
还有人知道吗?
#9
...
#10
..................
#11
只显示不重复的记录
sql="Select DISTINCT frdm From com"
sql="Select DISTINCT frdm From com"
#12
删除
就用 sql=delete from com where id not in (Select DISTINCT frdm,id From com)
我感觉好像写错了!可原理是这样!希望你能看明白
就用 sql=delete from com where id not in (Select DISTINCT frdm,id From com)
我感觉好像写错了!可原理是这样!希望你能看明白
#13
DISTINCT 是对于完全相同的记录而言的吧,我现在数据库里的只是某个字段数据相同,不是所有字段都这样啊
#14
delect from com
where id not in
(
select max(id) from com group by frdm
)
说的对,用group by就可以了
where id not in
(
select max(id) from com group by frdm
)
说的对,用group by就可以了
#15
呵呵!
#16
up
#17
显示:
select * from com
where id in
(
select min(id) from com group by frdm
)
删除:
delete from com
where id not in
(
select min(id) from com group by frdm
)
select * from com
where id in
(
select min(id) from com group by frdm
)
删除:
delete from com
where id not in
(
select min(id) from com group by frdm
)
#1
dim sql
sql="Select DISTINCT * From com"
Set objrs=Server.CreateObject("ADODB.RecordSet")
objrs.Open '打开数据库
sql="Select DISTINCT * From com"
Set objrs=Server.CreateObject("ADODB.RecordSet")
objrs.Open '打开数据库
#2
一个表中的frdm(法人代码)这个字段有重复,如何该删除重复的记录或者只显示不重复的记录...
举例说明:
com表:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
3 中南电脑 0125 ....
4 中南电脑 0125 ....
5 金鑫通迅 6587 ....
6 江南皮革 0265 ....
我要的结果记录集是:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
5 金鑫通迅 6587 ....
应该如何写sql语句
说明:数据库为Access数据,SQL语句必须能在Access里正确执行
引用-----------------------------
这不叫删除,用 distinct 筛选
举例说明:
com表:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
3 中南电脑 0125 ....
4 中南电脑 0125 ....
5 金鑫通迅 6587 ....
6 江南皮革 0265 ....
我要的结果记录集是:
id frmc frdm addr
1 中南电脑 0125 ....
2 江南皮革 0265 ....
5 金鑫通迅 6587 ....
应该如何写sql语句
说明:数据库为Access数据,SQL语句必须能在Access里正确执行
引用-----------------------------
这不叫删除,用 distinct 筛选
#3
select distinct * from com into temp
delete from com
select * from temp into com
delete from com
select * from temp into com
#4
SELECT TOP 1000 * FROM FCXX_zF WHERE (((FCXX_zF.ID) In (SELECT ID FROM FCXX_zF GROUP BY ID HAVING COUNT(*) > 1))) ORDER BY FCXX_zF.ID DESC;
这是我以前解决类似问题的方法,参考一下
这是我以前解决类似问题的方法,参考一下
#5
我上面举的例子有点问题,并不是完全相同的记录,所以用distinct是不行的
举例说明:
com表:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 65
3 中南电脑 0125 .... 34
4 中南电脑 0125 .... 54
5 金鑫通迅 6587 .... 34
6 江南皮革 0265 .... 23
我要的结果记录集是:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 45
5 金鑫通迅 6587 .... 34
举例说明:
com表:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 65
3 中南电脑 0125 .... 34
4 中南电脑 0125 .... 54
5 金鑫通迅 6587 .... 34
6 江南皮革 0265 .... 23
我要的结果记录集是:
id frmc frdm addr field2 ...
1 中南电脑 0125 .... 45
2 江南皮革 0265 .... 45
5 金鑫通迅 6587 .... 34
#6
根据frdm这个字段,只要这个字段相同的就去掉相同的记录
#7
delect from com
where id not in
(
select max(id) from com group by frdm
)
where id not in
(
select max(id) from com group by frdm
)
#8
还有人知道吗?
#9
...
#10
..................
#11
只显示不重复的记录
sql="Select DISTINCT frdm From com"
sql="Select DISTINCT frdm From com"
#12
删除
就用 sql=delete from com where id not in (Select DISTINCT frdm,id From com)
我感觉好像写错了!可原理是这样!希望你能看明白
就用 sql=delete from com where id not in (Select DISTINCT frdm,id From com)
我感觉好像写错了!可原理是这样!希望你能看明白
#13
DISTINCT 是对于完全相同的记录而言的吧,我现在数据库里的只是某个字段数据相同,不是所有字段都这样啊
#14
delect from com
where id not in
(
select max(id) from com group by frdm
)
说的对,用group by就可以了
where id not in
(
select max(id) from com group by frdm
)
说的对,用group by就可以了
#15
呵呵!
#16
up
#17
显示:
select * from com
where id in
(
select min(id) from com group by frdm
)
删除:
delete from com
where id not in
(
select min(id) from com group by frdm
)
select * from com
where id in
(
select min(id) from com group by frdm
)
删除:
delete from com
where id not in
(
select min(id) from com group by frdm
)