誰能告訴我以下sql查詢有什麼問題?嵌套的Sql select語句
Select *,
(SELECT [DiseaseID], COUNT(*) AS [Rank] FROM [DiseaseSymptom] WHERE
([SymptomID] IN(1, 5)) GROUP BY [DiseaseID] ORDER BY [Rank] DESC)
FROM Disease WHERE GenderID in (1, 3)
我有2代表一個含有疾病和性別它與
疾病
+-----------+-------------------+----------+
| DiseaseID | DiseaseName | GenderID |
+-----------+-------------------+----------+
| 1 | Fever | 3 |
| 2 | Flu | 3 |
| 3 | Lady Disease | 2 |
| 4 | Gentlemen Disease | 1 |
+-----------+-------------------+----------+
性別1 =男,2 =女性,3 =普通
相關聯和這樣的症狀疾病矩陣
DiseaseSymptom
+-----------+-----------+----------+
| DiseaseID | SymptomID | DissymID |
+-----------+-----------+----------+
| 1 | 1 | 1 |
| 1 | 2 | 3 |
| 1 | 4 | 4 |
| 2 | 1 | 5 |
| 2 | 3 | 9 |
| 2 | 4 | 6 |
| 2 | 5 | 7 |
+-----------+-----------+----------+
我從用戶的症狀,並在DiseaseSymptom
表相匹配,並根據匹配的症狀的數目(內SQL語句)
在外聲明我只是想獲得它排在內部陳述的結果並評估它是否屬於特定性別。我收到的時候我嘗試運行上述查詢的錯誤是
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
你想達到什麼目的? – Mureinik
你有什麼錯誤? – underscore
現在,我明白查詢要做什麼,我不是100%確定它是按照你的意圖做的。您應該提供樣本數據,期望的結果和(通常)說出現問題時會出現什麼問題。 –