我遇到了我的邏輯問題。請幫忙。使用連接進行計數
我得到的錯誤是: Msg 8120, Level 16, State 1, Line 603 Column 'Client.LastName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Msg 147, Level 15, State 1, Line 605 An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
我不知道如何做一個內部子查詢與計數功能。
- 編寫存儲過程調用NoJobs返回客戶名字,姓氏和PhoneNumber所有還沒有工作的客戶端。不要使用連接。 (2分)
Go
Create Procedure NoJobs (@ClientID int = null)
as
If @ClientID is null
Begin
RaisError ('Must provide Client ID',16,1)
End
Else
Begin
Select FirstName,LastName,Phone from Client
group by FirstName,LastName,Phone
having ClientID = (Select Count(*) from Job where Count(*) = 0 group by ClientID)
End
Return
太感謝你了,我做了otherquestions這種邏輯...我不知道我錯過了多少感覺:) – Lost