- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Delphi 2010 (TADOQuery) 中使用 ADO 数据库。
目标是找到可用的房间并显示一个小型 INN 的房价。
t_room
coderoom as string
coderoomtype as string
coderoomtype as string
nameroomtype as string
priceroomtype as number
datetrans as date
codepoeple as string
coderoom as string
dateintrans as date -> date check in
dateouttrans as date -> date check out
SELECT
t_room.coderoom, t_room.coderoomtype, t_roomtype.coderoomtype,
t_roomtype.nameroomtype, t_roomtype.priceroomtype
FROM
t_room
INNER JOIN
t_roomtype ON t_room.coderoomtype = t_roomtype.coderoomtype
ORDER BY
t_room.coderoom ASC;
coderoom | nameroomtype | priceroomtype
----------------------------------------
101 | VIP | 20
102 | VIP | 20
103 | Standart | 10
104 | Standart | 10
105 | Standart | 10
106 | Standart | 10
NOT IN
运算符):
SELECT
t_room.coderoom, t_room.coderoomtype, t_room.notesroom,
t_roomtype.coderoomtype, t_roomtype.nameroomtype, t_roomtype.priceroomtype
FROM
t_room
INNER JOIN
t_roomtype ON t_room.coderoomtype = t_roomtype.coderoomtype
WHERE
t_room.coderoom NOT IN (SELECT *
FROM t_trans
WHERE [current book/checkin/out date not between dateintrans and dateoutrans]
ORDER BY coderoom ASC)
ORDER BY
t_room.coderoom ASC;
$7701C41F - Exception class EOleException with message "You have writen a subquest that can return more than one field without using EXISTS reserved word in the main query's FROM clause. Revise the SELECT statement of the subquery to request only one field."
AQRoomAvailable1.SQL.Text := 'SELECT t_room.coderoom, t_room.coderoomtype, t_room.notesroom, t_roomtype.coderoomtype, t_roomtype.nameroomtype, t_roomtype.priceroomtype ';
AQRoomAvailable1.SQL.Text := AQRoomAvailable1.SQL.Text + 'FROM t_room INNER JOIN t_roomtype ON t_room.coderoomtype = t_roomtype.coderoomtype WHERE t_room.coderoom ';
AQRoomAvailable1.SQL.Text := AQRoomAvailable1.SQL.Text + 'NOT IN (SELECT * FROM t_trans x WHERE x.coderoom = t_room.coderoom AND ( (x.dateintrans BETWEEN ' + DateToStr(dtpDateIn1.Date) + ' AND ' + DateToStr(dtpDateOut1.Date) + ' ) ';
AQRoomAvailable1.SQL.Text := AQRoomAvailable1.SQL.Text + 'OR (x.dateouttrans BETWEEN ' + DateToStr(dtpDateIn1.Date) + ' AND ' + DateToStr(dtpDateOut1.Date) + ' ) ';
AQRoomAvailable1.SQL.Text := AQRoomAvailable1.SQL.Text + 'OR (' + DateToStr(dtpDateIn1.Date) + ' BETWEEN x.dateintrans AND x.dateouttrans) ) )';
最佳答案
SQL 似乎不是这个问题的主要问题。要找到所有研磨范围,您必须区分 4 种情况,其中情况 2 是情况 1 或 3 的特殊情况。
Declare @SW datetime
Declare @EW datetime
Select @SW=:SW
Select @EW=:EW
SELECT
t_room.coderoom, t_room.coderoomtype,
t_roomtype.coderoomtype, t_roomtype.nameroomtype, t_roomtype.priceroomtype
FROM
t_room
INNER JOIN
t_roomtype ON t_room.coderoomtype = t_roomtype.coderoomtype
WHERE
t_room.coderoom NOT IN (SELECT x.coderoom
FROM t_trans x
WHERE
(x.dateouttrans between @SW and @EW )
OR (x.dateintrans between @SW and @EW )
OR (@SW between x.dateintrans and x.dateouttrans)
)
ORDER BY
t_room.coderoom ASC;
SELECT
t_room.coderoom, t_room.coderoomtype,
t_roomtype.coderoomtype, t_roomtype.nameroomtype, t_roomtype.priceroomtype
FROM
t_room
INNER JOIN
t_roomtype ON t_room.coderoomtype = t_roomtype.coderoomtype
WHERE
t_room.coderoom NOT IN (SELECT x.coderoom
FROM t_trans x where
(x.dateouttrans between :SW and :EW )
OR (x.dateintrans between :SW1 and :EW1 )
OR (:SW2 between x.dateintrans and x.dateouttrans)
)
ORDER BY
t_room.coderoom ASC;
procedure TFMain.actRoomCheckIn1Execute(Sender: TObject);
begin
if (dtpDateOut1.Date >= dtpDateIn1.Date) then
begin
AQRoomAvailable1.Close;
AQRoomAvailable1.Parameters.ParamByName('SW').Value := dtpDateIn1.Date;
AQRoomAvailable1.Parameters.ParamByName('EW').Value := dtpDateOut1.Date;
AQRoomAvailable1.Parameters.ParamByName('SW1').Value := dtpDateIn1.Date;
AQRoomAvailable1.Parameters.ParamByName('EW1').Value := dtpDateOut1.Date;
AQRoomAvailable1.Parameters.ParamByName('SW2').Value := dtpDateIn1.Date;
AQRoomAvailable1.Open;
end
else
begin
AQRoomAvailable1.Active := False;
end;
end;
关于Sql 查询可用房间 - Delphi 2010 的 INN 或小型酒店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20017480/
Test1和Test2在同一个包中,为什么我需要导入test2? 如果我不使用import,Inn inn1 = test2.new Inn(4),就会出错。 &&其他问题: public void
我在 Delphi 2010 (TADOQuery) 中使用 ADO 数据库。 目标是找到可用的房间并显示一个小型 INN 的房价。 t_room coderoom as string cod
我有一个名为 hotel 的表,其中包含以下信息: Hotel_Id:2950 Hotel_Name:公园旅馆 酒店编号:01234567 Hotel_TypeId:1 我需要能够搜索名称列包含某些术
我不太了解 iOS 如何处理 URL,但它似乎在我的手机上做了一些奇怪的事情...... 我们的应用程序中有一个“赞”按钮,单击该按钮后应该会打开 Facebook 应用程序(如果未安装 Facebo
我的项目中有两个表。 POSTS 表 p_id p_user_id p_title p_description ...............................
Caused by: java.lang.NoClassDefFoundError: com.inn.wireless.data.Users at com.inn.activi
我是一名优秀的程序员,十分优秀!