|
源代码网推荐
源代码网整理以下
比如:
Name Adress Tele
1 Yao China 110
2 Zhang Moon 110
3 Wang China 110
4 Wang China 110
5 Yao China 110
根据姓名字段检索以后,能筛选出的记录有:1,3,4,5
select b.id from table as b,(select count(field),field from table where count(field)>2 group by field) as a where a.field=b.field
SELECT id from tb where dcount("id","tb","name=""&name&""")>1
附:
DCount Function
See Also Specifics
You can use the DCount function to determine the number of records that are in a specified set of records (a domain). Use the DCount function in Visual Basic, a macro, a query expression, or a calculated control.
For example, you could use the DCount function in a module to return the number of records in an Orders table that correspond to orders placed on a particular date.
DCount(expr, domain, [criteria])
The DCount function has the following arguments.
Argument Description
expr An expression that identifies the field for which you want to count records. It can be a string expression identifying a field in a table or query, or it can be an expression that performs a calculation on data in that field. In expr, you can include the name of a field in a table, a control on a form, a constant, or a function. If expr includes a function, it can be either built-in or user-defined, but not another domain aggregate or SQL aggregate function.
domain A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.
criteria An optional string expression used to restrict the range of data on which the DCount function is performed. For example, criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE. If criteria is omitted, the DCount function evaluates expr against the entire domain. Any field that is included in criteria must also be a field in domain; otherwise the DCount function returns a Null.
Remarks
Use the DCount function to count the number of records in a domain when you don"t need to know their particular values. Although the expr argument can perform a calculation on a field, the DCount function simply tallies the number of records. The value of any calculation performed by expr is unavailable.
Use the DCount function in a calculated control when you need to specify criteria to restrict the range of data on which the function is performed. For example, to display the number of orders to be shipped to California, set the ControlSource property of a text box to the following expression:
=DCount("[OrderID]", "Orders", "[ShipRegion] = "CA"")
If you simply want to count all records in domain without specifying any restrictions, use the Count function.
Tip The Count function has been optimized to speed counting of records in queries. Use the Count function in a query expression instead of the DCount function, and set optional criteria to enforce any restrictions on the results. Use the DCount function when you must count records in a domain from within a code module or macro, or in a calculated control.
You can use the DCount function to count the number of records containing a particular field that isn"t in the record source on which your form or report is based. For example, you could display the number of orders in the Orders table in a calculated control on a form based on the Products table.
The DCount function doesn"t count records that contain Null values in the field referenced by expr unless expr is the asterisk (*) wildcard character. If you use an asterisk, the DCount function calculates the total number of records, including those that contain Null fields. The following example calculates the number of records in an Orders table.
intX = DCount("*", "Orders")
If domain is a table with a primary key, you can also count the total number of records by setting expr to the primary key field, since there will never be a Null in the primary k
源代码网供稿. |