访问:比较不同表格中的数字

时间:2017-06-29 20:03:01

标签: database ms-access database-design ms-office

我不太了解Microsoft Access,但我需要它来解决这个问题:

我们假设我有两张桌子:

表A:

Zipcode Start | ZipCode End | Etc1          | Etc2
==============================================================
20000-000     | 29999-999   | Sample data 1 | Another Sample 1
30000-000     | 39999-999   | Sample data 2 | Another Sample 2
40000-000     | 49999-999   | Sample data 3 | Another Sample 3

表B:

NAME     | ZipCode   |  Etc1   |    Etc2
=============================================
John Doe | 31564-888 |         |
Johnny   | 22559-010 |         |
James    | 44411-000 |         |

如何将表B 上的Zipcodes与表A上的指定范围进行比较?并返回" Etc1"和" Etc2"匹配吗?

谢谢大家!!

1 个答案:

答案 0 :(得分:0)

你可以这样做:

Select 
    TableB.Name,
    TableB.ZipCode,
    TableA.Etc1,
    TableA.Etc2
From
    TableA,
    TableB
Where
    TableB.ZipCode Between TableA.[ZipCode Start] And TableA.[ZipCode End]