如何在2个表中获得结果 [英] How do I get a result across 2 tables
问题描述
我有2张桌子。一个叫做预订,另一个叫做房间。预订中的列包括:RoomID,startdate,enddate,customerId。房间中的列是:RoomID,大小。
I have 2 tables. One is called booking and another one is called room. The columns in booking are: RoomID, startdate, enddate, customerId. The columns in room is: RoomID, size.
我想从预订表中选择一行,其中日期在startdate和enddate之间且大小相等无论我作为一个论点传递。例如:
I want to select a row from the booking table where a date is between the startdate and the enddate and the size is equal whatever I pass in as an argument. E.g.:
我想在2010-01-31和2010-02-25之间进行选择,其中size = Large。
I want to select between 2010-01-31 and 2010-02-25 where size = Large.
编辑=这就是我所做的: String sqlStatement =SELECT StartDate,EndDate FROM Booking from+ startD +,+ endD;
EDIT = THIS IS WHAT I HAVE SO FAR: String sqlStatement = "SELECT StartDate, EndDate FROM Booking between " + startD + ", " + endD;
推荐答案
试用此代码
SELECT booking.*
FROM booking JOIN room USING(RoomID)
WHERE column_name BETWEEN startdate AND enddate AND size = @size_input;
这篇关于如何在2个表中获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!