使用一个表中的数据从另一个表中获取数据
我有点困惑。我为此使用 SSMS。
“对于客户 Ryan Goff 的每次预订,请列出预订 ID、行程 ID 和人数。”
Ryan Goff 位于主键为 CUSTOMER_NUM 的 CUSTOMER 表中。 所有其他都在 RESERVATION 表中,主键是 RESERVATION_ID,外键是 CUSTOMER_NUM
我如何仅从姓名中获取预订 ID、行程 ID 和人数的列表?我是否还需要获取人员 CUSTOMER_NUM 才能连接这些值?我该怎么做呢?
粗体 = 主键
CUSTOMER(CUSTOMER_NUM, LAST_NAME, ADDRESS, CITY, STATE, POSTAL_CODE, PHONE)
预订(RESERVATION_ID, TRIP_ID, TRIP_DATE, NUM_PERSONS 、TRIP_PRICE、OTHER_FEES、CUSTOMER_NUM)
I'm a little bit confused. I'm using SSMS for this.
"For each reservation for customer Ryan Goff, list the reservation ID, trip ID, and number of persons."
Ryan Goff is in the CUSTOMER table with the primary key being CUSTOMER_NUM.
All the others are in the RESERVATION table with the primary key being RESERVATION_ID and the foreign key being CUSTOMER_NUM
How would I get the list the reservation ID, trip ID, and number of persons just from the name? Wouldn't I also need to get the persons CUSTOMER_NUM in order to connect the values? How would I do that?
Bold = Primary Key
CUSTOMER(CUSTOMER_NUM, LAST_NAME, ADDRESS, CITY, STATE, POSTAL_CODE, PHONE)
RESERVATION(RESERVATION_ID, TRIP_ID, TRIP_DATE, NUM_PERSONS, TRIP_PRICE, OTHER_FEES, CUSTOMER_NUM)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 IN 运算符与子查询结合使用来执行此操作。
这个确切问题的一个例子是:
You can use the IN operator with a subquery to do this.
An example for this exact question would be:
实现此目的的最佳方法是通过外键连接表,该外键将是客户表中的主键。见下文:
The best way to achieve this is by joining the tables on the foreign key which would be the primary key in the customer table. See below: