Microsoft Access中有V查找效果吗?

时间:2019-02-28 17:42:26

标签: forms ms-access

我是新手,自学Microsoft Access。

我有一个MS Access数据库,其中有一个学生表(表1)。

表1

+----+-----------+----------+------------+------------+
| id | firstname | lastname | Year_Group | Form_Group |
+----+-----------+----------+------------+------------+
|  2 | mnb       | nbgfv    |          7 |          1 |
|  3 | jhg       | uhgf     |          8 |          2 |
|  4 | poi       | ijuy     |          9 |          2 |
|  5 | tgf       | tgfd     |         10 |          2 |
|  6 | wer       | qwes     |         11 |          2 |
+----+-----------+----------+------------+------------+

每天的学生日记录类似于表2。

表2

+----------+----+-----------+----------+------------+--------+-----------+----------+
|   Date   | id | firstname | lastname | Year_Group | Effort | Behaviour | Homework |
+----------+----+-----------+----------+------------+--------+-----------+----------+
| 28/02/19 |  2 | mnb       | nbgfv    |          7 | Good   | Good      | Y        |
| 28/02/19 |  3 | jhg       | uhgf     |          8 | OK     | OK        | Y        |
| 28/02/19 |  4 | poi       | ijuy     |          9 | Bad    | Bad       | N        |
| 01/03/19 |  5 | tgf       | tgfd     |         10 | Good   | OK        | Y        |
| 01/03/19 |  6 | wer       | qwes     |         11 | Good   | Good      | Y        |
+----------+----+-----------+----------+------------+--------+-----------+----------+

有没有办法(当使用列表框或组合框时)从Table1中选择一个学生,以便其信息用于Table2中的相应列?

还是有一种更有效的方法?

1 个答案:

答案 0 :(得分:2)

首先,您应该 normalise your data

当前,您正在两个单独的表中重复firstnamelastnameYear_Group数据,这不仅使数据库your肿,而且还意味着必须在两个不同的地方,可能会导致不一致,然后导致不确定哪个是主要角色。

相反,我建议您的Students表应包含与学生特征有关的所有信息:

学生

+----+-----------+----------+------------+------------+
| id | firstname | lastname | Year_Group | Form_Group |
+----+-----------+----------+------------+------------+
|  2 | mnb       | nbgfv    |          7 |          1 |
|  3 | jhg       | uhgf     |          8 |          2 |
|  4 | poi       | ijuy     |          9 |          2 |
|  5 | tgf       | tgfd     |         10 |          2 |
|  6 | wer       | qwes     |         11 |          2 |
+----+-----------+----------+------------+------------+

与每个上学日有关的信息应仅引用Students表中的学生ID:

学校日

+----------+----+--------+-----------+----------+
|   Date   | id | Effort | Behaviour | Homework |
+----------+----+--------+-----------+----------+
| 28/02/19 |  2 | Good   | Good      | Y        |
| 28/02/19 |  3 | OK     | OK        | Y        |
| 28/02/19 |  4 | Bad    | Bad       | N        |
| 01/03/19 |  5 | Good   | OK        | Y        |
| 01/03/19 |  6 | Good   | Good      | Y        |
+----------+----+--------+-----------+----------+

然后,如果要完整显示数据,则可以使用将两个表连接起来的查询,例如:

select  
    t2.date,
    t1.firstname,
    t1.lastname, 
    t1.year_group, 
    t2.effort, 
    t2.behaviour, 
    t2.homework
from 
    students t1 inner join schooldays t2 on t1.id = t2.id