我在努力讓這段代碼正常工作,我想要做的是選擇多個列名稱,然後將結果按同一個表中的其他兩列分組。按分組嵌套選擇語句
但我似乎無法得到正確的語法,所以任何有比我更多的SQL服務器經驗誰可以幫助我這將不勝感激。
我正在尋找的是返回基於緯度非重複的結果,東經
實際代碼
SELECT [CityName] AS CityName,
ISNULL(NULLIF([CountyName],''),'') AS CountyName,
[CityLatitude] AS Latitude,
[CityLongitude] AS Longitude
FROM [dbo].[tblCityLatitudeLongitudes]
WHERE [CountryName] = @Country
ORDER by [CityName] ASC
OFFSET @OffSet ROWS
FETCH NEXT 10 ROWS ONLY;
我已經嘗試了各種方式,以下是我的最後一次嘗試,但仍然拋出錯誤
SELECT a.CityName AS CityName,
ISNULL(NULLIF(a.CountyName,''),'') AS CountyName,
a.CityLatitude AS Latitude,
a.CityLongitude AS Longitude
FROM
(SELECT b.CityLatitude,b.CityLongitude
FROM tblCityLatitudeLongitudes b
WHERE b.CountryName = 'united kingdom'
GROUP BY b.CityLatitude,b.CityLongitude) a
錯誤
Msg 207, Level 16, State 1, Line 24
Invalid column name 'CityName'.
Msg 207, Level 16, State 1, Line 25
Invalid column name 'CountyName'.
Msg 207, Level 16, State 1, Line 25
Invalid column name 'CountyName'.
您可加入tblCityLatitudeLongitudes' – bummi 2014-10-30 23:04:48
@bummi的'的sheam不知道你的意思 – 2014-10-30 23:08:42
邊注:在'ISNULL(NULLIF([CountyName], ''), '')的''NULLIF'似乎多餘的,'ISNULL([CountyName],'')'會給你同樣的結果。 – 2014-10-30 23:26:02