我有以下SQL查詢:SQL子查詢由
SELECT
kvknum.cd_hfdrelnr,
kvknum.cd_kvkanum,
relName.cd_hfdrelnr
FROM
(
SELECT
cd_hfdrelnr,
cd_kvkanum
FROM er_105
WHERE cd_kvkanum IN
(
SELECT cd_kvkanum
FROM er_105
GROUP BY cd_kvkanum
HAVING COUNT(*) > 1
)
AND cd_kvkanum != ''
ORDER BY cd_kvkanum
) AS kvknum
LEFT OUTER JOIN
(
SELECT
cd_hfdrelnr,
cd_relnaam
FROM er_101
) AS relName
ON kvknum.cd_hfdrelnr = relName.cd_hfdrelnr
的GROUP BY
功能是不允許的,它是需要這樣相同cd_kvkanum
值下彼此一起示出,有一個變通對於這個或者這個可能如何實現?
跟隨誤差與它來:
「消息1033,級別15,狀態1,行21 ORDER BY子句在視圖,內聯函數,派生表,子查詢無效,公用表表達式,除非TOP或FOR XML也被指定 Msg 156,Level 15,State 1,Line 28 關鍵字'AS'附近的語法不正確。
當我運行以下查詢:
SELECT
cd_hfdrelnr,
cd_kvkanum
FROM er_105
WHERE cd_kvkanum IN
(
SELECT cd_kvkanum
FROM er_105
GROUP BY cd_kvkanum
HAVING COUNT(*) > 1
)
AND cd_kvkanum != ''
ORDER BY cd_kvkanum
(的加盟第一子查詢)的結果如下:
1235 - 123
4652 - 123
8569 - 1234
4985 - 1234
雖然我想cd_relnaam添加到結果列表, 時,只需使用該查詢我的結果的JOIN是空白......
任何人知道我做錯了什麼?
示例數據?預期結果?你的意思是「儘管按功能分組是不允許的」。請嘗試在問題中添加* some *上下文。我們不介意讀者。 –
用更多的信息更新:) –