我想拉0个值但是我的查询不允许0值,执行时间很长。
这是我的代码:
select a.Owner_Id,
b.Name as KPI,
B.Record_Type,
B.Resource_Id,
C.Display_Name,
count(*) as Max
from amgr_appointments A
right outer join AMGR_Resources B on A.Owner_Id = b.Resource_Id
right outer JOIN ADMN_User_Details AS C ON A.Creator_Id=C.User_Id
where b.Resource_Id in ('ROE534B758E', 'R0E42A431B5', 'R0E42A4BB3F','R0E42A3E514','R0E42A44D19', 'R0E42A37FBB')
and b.Record_Type = 3
and a.Creator_Id In('AMCKENZIE','ASARAK', 'JMALAN')
and A.App_Date between '2016-02-29'and '2016-03-29'
Group by a.Owner_Id, a.Creator_Id, b.Name, B.Record_Type, B.Resource_Id, c.Display_Name
我得到以下结果:
amckenzie 1 Pop-in
ASARAK 2 Pop-in
但是我希望这个结果包括用户即使值为0
amckenzie 1 Pop-in
ASARAK 2 Pop-in
JMALAN 0 Pop-in
请帮帮我,告诉我哪里出了问题。我尝试了不同的连接,但查询运行时间过长
答案 0 :(得分:0)
尝试以下
SELECT a.Owner_Id,
b.Name as KPI,
B.Record_Type,
B.Resource_Id,
C.Display_Name,
count(*) as Max
FROM amgr_appointments A
RIGHT OUTER JOIN AMGR_Resources B
ON (A.Owner_Id = b.Resource_Id
AND a.Creator_Id In('AMCKENZIE','ASARAK', 'JMALAN')
AND A.App_Date BETWEEN '2016-02-29'AND '2016-03-29')
RIGHT OUTER JOIN ADMN_User_Details AS C
ON (A.Creator_Id = C.User_Id)
WHERE b.Resource_Id in ('ROE534B758E', 'R0E42A431B5', 'R0E42A4BB3F','R0E42A3E514','R0E42A44D19', 'R0E42A37FBB')
AND b.Record_Type = 3
GROUP BY a.Owner_Id, a.Creator_Id, b.Name, B.Record_Type, B.Resource_Id, c.Display_Name