サブクエリを使用して count(*) を記述するにはどうすればよいですか?
select count(*) from Firms
select count(*) from (select * from Firms)
上記の 2 行では、一番上の行は機能しますが、2 行目でエラーが発生します。
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.
しかし、(select * from Firms)
==ではありませんFirms
か?
編集: ただし、これについては:
select count(*) from
(
select HireResponseID, HireResponse, DateResponse, Comments, YearFileOpened, file_number, isCaseOpen, last_update, isConfidential, date_created, OurClient, TheirClient, ProjectName, description, lawyer_lastname, lawyer_firstname, Conflicts.ConflictID
from Hire_Response, Conflicts, Lawyers
WHERE Hire_Response.ConflictID=Conflicts.ConflictID AND Lawyers.lawyerID=Conflicts.lawyerID AND firmID = @FirmID AND HireID = @HireID AND isStillaConflict = 1
ORDER BY file_number, TheirClient, OurClient, lawyer_lastname, lawyer_firstname
) as data
エラーが発生します:
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.
どうすればこれを修正できますか?