简体   繁体   English

有没有办法根据两个条件过滤 ms-Access 记录?

[英]Is there a way to filter ms-Access records based on two criteria?

i'm not experinced when it comes to Microsoft Access and i'm having diffuclties completeling a task at my internship.我对 Microsoft Access 没有经验,而且我在实习期间很难完成任务。 I was given a list of records and i'm supposed to create a query that picks random records (winners) based on the country and the year of choice.我得到了一个记录列表,我应该创建一个查询,根据国家和选择的年份选择随机记录(获奖者)。 I was able to do the randomizing bit by implementing the following SQL code:我能够通过实现以下 SQL 代码来完成随机化位:

     `SELECT TOP 10 Sheet2.name, Sheet2.country, Sheet2.Year
      FROM Sheet2
      ORDER BY Rnd(-(100000*ID)*Time());

` `

My problem is that I want to choose the number of winners and select the country from dropdown list in my form and the year and filter the records based on the selection.我的问题是我想选择获胜者的数量,并从表单和年份的下拉列表中选择国家,并根据选择过滤记录。

Any help would be appreciated!任何帮助,将不胜感激!

This should work:这应该有效:

  SELECT TOP 10 Sheet2.name, Sheet2.country, Sheet2.Year
  FROM Sheet2
  WHERE Sheet2.country = [Forms]![YourFormName]![cboCountry]
  AND Sheet2.Year = [Forms]![YourFormName]![txtYear]
  ORDER BY Rnd(-(100000*ID)*Time());

where cboCountry and txtYear are the two controls on your form.其中cboCountrytxtYear是表单上的两个控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM