我正在尝试返回别墅预订系统的最低和最高价格。我有一个查找表,存储每个别墅每周的价格。
我在选择中使用 min 和 max 函数来执行此操作,但我遇到了很多问题。谁能解释我哪里出错了?这里是sp
ALTER PROCEDURE spVillaGet
-- Add the parameters for the stored procedure here
@accomodationTypeFK int = null,
@regionFK int = null,
@arrivalDate datetime = null,
@numberOfNights int = null,
@sleeps int = null,
@priceFloor money = null,
@priceCeil money = null
AS BEGIN -- 添加了 SET NOCOUNT ON 以防止额外的结果集 -- 干扰 SELECT 语句。设置无计数;
-- Insert statements for procedure here
SELECT tblVillas.name,
tblVillas.introduction,
tblVillas.italian_introduction,
tblVillas.uk_content,
tblVillas.italian_content,
tblVillas.sleeps,
tblVillas.postcode,
tblLkUpRegions.regionName,
tblLkUpAccomodationTypes.accomodationType,
MIN(price) As MinPrice,
MAX(price) As MaxPrice
FROM tblVillas
LEFT JOIN tblLkUpRegions on tblVillas.regionFK = tblLkUpRegions.regionID
LEFT JOIN tblLkUpAccomodationTypes on tblVillas.accomodationTypeFK = tblLkUpAccomodationTypes.accomodationId
LEFT JOIN tblWeeklyPrices on tblWeeklyPrices.villaFK = tblVillas.villaId
WHERE
((@accomodationTypeFK is null OR accomodationTypeFK = @accomodationTypeFK)
AND (@regionFK is null OR regionFK = @regionFK)
AND (@sleeps is null OR sleeps = @sleeps)
AND tblVillas.deleted = 0)
GROUP BY tblVillas.name