Member 12400712 Ответов: 1

Как получить свободные номера


help me
The sql statement obtains the free space in the attached table, the roomAvailable field is the number of available rooms that day, the sql statement must now check for room availability from date to date.

this is structure table

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RoomRate](
	[roomRateID] [int] IDENTITY(1,1) NOT NULL,
	[roomID] [int] NOT NULL,
	[roomRate] [float] NOT NULL,
	[roomAvailable] [int] NOT NULL,
	[roomRateDate] [date] NOT NULL,
	[roomRateState] [bit] NOT NULL,
 CONSTRAINT [PK_RoomRate] PRIMARY KEY CLUSTERED 
(
	[roomRateID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[RoomRate] ON
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (1, 55, 100, 4, CAST(0xCC3D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (2, 55, 100, 3, CAST(0xCD3D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (3, 55, 100, 1, CAST(0xCE3D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (4, 55, 100, 0, CAST(0xCF3D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (5, 55, 100, 3, CAST(0xD03D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (6, 55, 100, 0, CAST(0xD13D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (7, 55, 100, 5, CAST(0xD23D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (8, 55, 100, 3, CAST(0xD33D0B00 AS Date), 1)
INSERT [dbo].[RoomRate] ([roomRateID], [roomID], [roomRate], [roomAvailable], [roomRateDate], [roomRateState]) VALUES (9, 55, 100, 2, CAST(0xD43D0B00 AS Date), 1)
SET IDENTITY_INSERT [dbo].[RoomRate] OFF
/****** Object:  Default [DF_RoomRate_roomRate]    Script Date: 01/25/2018 20:05:29 ******/
ALTER TABLE [dbo].[RoomRate] ADD  CONSTRAINT [DF_RoomRate_roomRate]  DEFAULT ((0)) FOR [roomRate]
GO
/****** Object:  Default [DF_RoomRate_roomRateState]    Script Date: 01/25/2018 20:05:29 ******/
ALTER TABLE [dbo].[RoomRate] ADD  CONSTRAINT [DF_RoomRate_roomRateState]  DEFAULT ((1)) FOR [roomRateState]
GO


Что я уже пробовал:

how to get rooms available

nitrous_007

Измените название вашего вопроса на что-то более актуальное. Комнаты-это нечто, имеющее отношение только к вам. Если кто-то увидит название вопроса, он не поймет, о чем вы говорите.

Rajesh Pandya

Вы дали только структуру таблицы. Какой запрос вы уже пробовали? Какую ошибку вы получили? Пожалуйста, уточните это.

ZurdoDev

Где ты застрял?

CHill60

На отдельной ноте - зачем создавать столбец идентификаторов, а затем самостоятельно предоставлять roomRateID? Бессмысленный.

1 Ответов

Рейтинг:
1

Maciej Los

Это совершенно очевидно... Вы должны использовать предложение WHERE[^]:

SELECT *
FROM RoomRate
WHERE roomRateDate BETWEEN '2018-01-01' AND '2018-01-31'


Для получения более подробной информации, пожалуйста, смотрите:
Выберите примеры (Transact-SQL) | Microsoft Docs[^]