简体   繁体   English

查询构建以查找所有一系列记录都具有值的记录

[英]Query build to find records where all of a series of records have a value

Let me explain a little bit about what I am trying to do because I dont even know the vocab to use to ask.让我解释一下我正在尝试做的事情,因为我什至不知道用来提问的词汇。 I have an Access 2016 database that records staff QA data.我有一个 Access 2016 数据库,用于记录员工 QA 数据。 When a staff member misses a QA we assign a job aid that explains the process and they can optionally send back a worksheet showing they learned about what was missed.当员工错过 QA 时,我们会分配一个工作帮助来解释该流程,他们可以选择发回一份工作表,显示他们了解了错过的内容。 If they do all of these ina 3 month period they get a credit on their QA score.如果他们在 3 个月内完成所有这些工作,他们将获得 QA 分数的积分。 So I have a series of records all of whom have a date we assigned the work(RA1) and MAY have a work returned date(RC1).所以我有一系列记录,所有这些记录都有我们分配工作的日期(RA1),并且可能有一个工作返回日期(RC1)。 在此处输入图像描述

In the below image "lavalleer" has earned the credit because both of her sheets got returned.在下图中,“lavalleer”获得了荣誉,因为她的两张床单都被退回了。 "maduncn" Did not earn the credit because he didn't do one. “maduncn”没有获得荣誉,因为他没有做一个。 I want to create a query that returns to me only the people that are like "lavalleer".我想创建一个查询,只返回像“lavalleer”这样的人。 I tried hitting google and searched here and access.programmers.co.uk but I'm only coming up with instructions to use Not null statements.我尝试点击谷歌并在此处搜索和 access.programmers.co.uk 但我只是提出使用 Not null 语句的说明。 That wouldn't work for me because if I did a IS Not Null on "maduncn" I would get the 4 records but it would exclude the null.这对我不起作用,因为如果我在“maduncn”上执行 IS Not Null,我会得到 4 条记录,但它会排除 null。

What I need to do is build a query where I can see staff that have dates in ALL of their RC1 fields.我需要做的是构建一个查询,我可以在其中查看在所有 RC1 字段中都有日期的员工。 If any of their RC1 fields are blank I dont want them to return.如果他们的任何 RC1 字段为空白,我不希望他们返回。

Consider:考虑:

SELECT * FROM tablename WHERE NOT UserLogin IN (SELECT UserLogin FROM tablename WHERE RCI IS NULL);

You could use a not exists clause with a correlated subquery, eg您可以将not exists的子句与相关的子查询一起使用,例如

select t.* from YourTable t where not exists 
(select 1 from YourTable u where t.userlogin = u.userlogin and u.rc1 is null)

Here, select 1 is used purely for optimisation - we don't care what the query returns, just that it has records (or doesn't have records).在这里, select 1纯粹用于优化 - 我们不关心查询返回什么,只关心它有记录(或没有记录)。


Or, you could use a left join to exclude those users for which there is a null rc1 record, eg:或者,您可以使用left join来排除那些有 null rc1记录的用户,例如:

select t.* from YourTable t left join
(select u.userlogin from YourTable u where u.rc1 is null) v on t.userlogin = v.userlogin
where v.userlogin is null

In all of the above, change all occurrences of YourTable to the name of your table.在上述所有内容中,将所有出现的YourTable更改为您的表的名称。

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

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