我有这样两个查询:
SELECT
count (C.CaseDetailsId) as [Z telefonem]
,U.FirstName + ' ' + U.LastName as [Windykator]
from CaseDetails as C
join DebtorDetails as D on C.CaseDetailsId = D.CaseDetailsId
join Users as U on C.UserId = U.UserId
where D.DebtorDetailsId in
(SELECT DebtorDetailsId from DebtorPhone
where (IsValid = 'True') or (IsDefault = 'True'))
and C.CaseStatusId <> 2 and C.CaseStatusId <> 6 group by U.FirstName,U.LastName
e
和
SELECT
count (CaseDetailsId) as [Beztel]
,U.FirstName + ' ' + U.LastName as [Windykator]
from CaseDetails as C
join Users as U on C.UserId = U.UserId
where
C.CaseStatusId <> 2 and C.CaseStatusId <> 6 group by U.FirstName,U.LastName
我需要将这两个结果分组到一张表中,所以我想最好将它们连接起来,但我不知道该怎么做。
查询必须在两种情况下计算行数 1) 总体 2) 在另一个表中存在指定行的位置
所以总的来说->我需要为每个有和没有电话号码(DebtorPhones)的员工(用户)计算案件数量(CaseDetailsId)