我能夠在SQL執行以下操作:SQL - 排序OVER子句中
SELECT ROW_NUMBER() OVER (ORDER BY c.SomeField2 ASC) AS r, c.cID
FROM
(
SELECT c.SomeField1, c.SomeField2, c.SomeField3, t.SomeField1Text, p.SomeField2Text
FROM MyTable c
JOIN #TempTable1 t ON c.SomeField1 = t.SomeField1
JOIN #TempTable2 p ON c.SomeField2 = p.SomeField2
) c
然而,當我嘗試從像這樣我的臨時表的一個列排序...
SELECT ROW_NUMBER() OVER (ORDER BY p.SomeField2Text ASC) AS r, c.cID
FROM
(
SELECT c.SomeField1, c.SomeField2, c.SomeField3, t.SomeField1Text, p.SomeField2Text
FROM MyTable c
JOIN #TempTable1 t ON c.SomeField1 = t.SomeField1
JOIN #TempTable2 p ON c.SomeField2 = p.SomeField2
) c
...我收到以下錯誤:
The multi-part identifier "p.SomeFieldText2" could not be bound.
你知道爲什麼我得到這個錯誤?我很困惑,因爲該專欄在我的SELECT
條款中。
我編輯了類型o在我的問題。我仍然有同樣的問題。 – WEFX 2014-11-06 16:05:47
你有沒有嘗試'ORDER BY c.SomeField2Text ASC'? – 2014-11-06 16:16:37
謝謝@ user2315555,我剛剛在看到Almazini的回答後試過。 – WEFX 2014-11-06 16:20:28