如何使用子查詢編寫計數(*)?如何從子查詢中計數(*)
select count(*) from Firms
select count(*) from (select * from Firms)
在上面的兩行,上一部作品,但在第二行中,我得到的錯誤:
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.
我該如何解決這個問題?
不僅是子句中的子查詢無效訂單,它不會告發」完成任何有用的事情。 –