我試圖返回別墅預訂系統的最低和最高價格。我有一張查詢表,用於存儲每個別墅每週的價格。sql - 使用聚合函數(最小/最大)作爲select語句的一部分
我使用最小和最大函數來做到這一點內選擇,但我有很多問題。任何人都可以解釋我要去哪裏錯了嗎?繼承人的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語句的干擾。 SET NOCOUNT ON;
-- 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
需要更多詳細信息,你正在得到什麼錯誤 – Greg 2008-11-26 10:37:44
有什麼問題,你面臨的錯誤? – Dheer 2008-11-26 10:39:21