如何比较相关表中的日期并使用它来选择查询中的相关记录? SQL/MS 访问
课程的细节会随着时间的推移而变化。我需要能够访问课程运行时这些详细信息的最新版本。
我的表格设置如下(仅显示相关字段):
课程详细信息
- ClassID(主键)
CourseID(外键)
开始日期
课程
- CourseID(主键)
课程版本
- CourseVersionID(主键)
CourseID (外键)
课程版本开始日期
我想在包含以下列的查询中为每个唯一 ClassID 显示一条记录:
ClassID< /p>
紧邻开始日期下方的课程版本开始日期(请参阅下面的示例)
课程版本开始日期 (1) = 01/01/2010
课程版本开始日期 (2) = 01/11/2011
开始日期在 (1) 和 (2) 之间 ~ 返回值为 01/01/2010
开始日期大于 (2) ~ 返回值为 01/11/2011
开始日期小于(1)~返回值无,该记录不显示。
- CourseVersionID
无需太多 SQL 知识(即在 Access 设计视图中)即可使用的解决方案是首选,但不是必需的。
The details of a course change over time. I need to be able to access the version of these details that was current when the course was run.
My tables are setup as follows (only relevant fields are shown):
Class Details
- ClassID (Primary key)
CourseID (Foreign key)
Commencement Date
Courses
- CourseID (Primary key)
Course Versions
- CourseVersionID (Primary key)
CourseID (Foreign key)
Course Version Start Date
I want to show one record per unique ClassID in a query with the following columns:
ClassID
The Course Version Start Date immediately below the Commencement Date (see examples below)
Course Version Start Date (1) = 01/01/2010
Course Version Start Date (2) = 01/11/2011
Commencement Date is between (1) and (2) ~ The returned value is 01/01/2010
Commencement Date is greater than (2) ~ The returned value is 01/11/2011
Commencement Date is less than (1) ~ The returned value is nothing, this record doesn't show up.
- CourseVersionID
Solutions that can be used without much SQL knowledge (ie within the Access design view) are prefered but not necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 SQL 中:
或者,由于您更喜欢访问查询设计器:
In SQL:
Or, since you prefer the access query designer:
不完全是查询设计窗口,尽管可以在那里查看,即使没有符合您第五个要求的日期,它也会返回一行。
Not quite query design window, though it can be viewed there, and it will return a line even if there is no date as per your fifth requirement.