我正在努力学习SQL。我有三张不同的桌子。所有的表都有一个公共列。我展示的是一小部分样本数据。我正在尝试理解如何在子表被更新后读取父表。
Table_1 (booking platform info)
booking_date column2 column3 column4 cust_country_id hotel_id booking_value
22-mar-2016 .................. 1001 1 $150
01-apr-2016 .................. 1002 2 $500
09-apr-2016 .................. 1001 2 $222
17-apr-2016 .................. 1002 4 $75
19-apr-2016 .................. 1003 1 $690
03-May-2016 ................., 1001 3 $301
Table_2 (hotel information)
hotel_id hotel_name hotel_country
1 Marriott Germany
2 Novotel France
3 Oberoi India
4 Osaka Japan
Table_3 (customer information)
country_id country_name
1001 India
1002 France
1003 Japan我的问题是,如果一家来自法国的凯悦酒店被添加到Table_2 (酒店信息)中,我如何才能找到法国客户预订该酒店的第一个日期?
我对如何处理这一点有点困惑;因为它必须从所有3个表中获取值。
发布于 2019-08-15 03:19:12
我认为在这种情况下,您应该编写mysql查询来查找来自法国的客户和名为Hyatt的酒店的最早的booking_date。
select booking_date from Table_1
join Table_2 on Table_2.hotel_id = Table_1.hotel_id
join Table_3 on Table_3.country_id = Table_1.cust_country_id
where Table_3.country_name = 'France' and Table_2.hotel_name = 'Hyatt'
order by Table_1.booking_date asc
limit 1https://stackoverflow.com/questions/57500503
复制相似问题