问题:
|
根据其中几个字段判断重复,只保留一条记录,但是要显示全部字段,怎么查询,谢谢!!
比如
字段1 字段2 字段3 字段4
a b c 1
a b c 1
a b d 2
a b d 3
b b d 2
想得到的结果为
a b c 1
a b d 2(或者3)
b b d 2
说明,根据字段1,2,3组合不重复,字段4 不考虑,得到了3个记录
但是也要显示字段4。
|
方法一:
|
可以用临时表的方法来解决:
CurrentProject.Connection.Execute "drop table temptable"
CurrentProject.Connection.Execute "select * into temptable from 表2 where 1=2"
CurrentProject.Connection.Execute "insert into temptable(字段1,字段2,字段3) Select DISTINCT 表2.字段1, 表2.字段2, 表2.字段3 FROM 表2;"
CurrentProject.Connection.Execute "Update temptable INNER JOIN 表2 ON (表2.字段1 = temptable.字段1) AND (表2.字段2 = temptable.字段2) AND (表2.字段3 = temptable.字段3) SET temptable.字段4 = [表2].[字段4];" |
|
Access软件网交流QQ群(群号:198465573) |
|