我有兩個表,我想加入和過濾數據。我用一個存儲過程來做到這一點。我的意圖是從第二張表(即部門)中提取每個項目,即使他們在第一個表格(即員工)中沒有匹配的記錄並最終顯示計數。以下是我使用的代碼段:右外連接問題
select d.deptName,
case when COUNT(*) is null then '0' else count(*) end AS total
from Employee e
right outer join Department d on e.deptID=d.deptID
WHERE [email protected]
and [email protected]
group by d.deptName
order by d.deptName
但是,它沒有顯示我想要的內容,但未能找出真正的問題。
是的,這查詢是很正確的,你可以使用它。 –