我要做的是列出最近的事件类型'1081'
但如果它是最近的事件类型,我只会获得'1081'。
另一种事件类型是'1009'
如果1009是最新的事件类型,则该记录根本不会出现。
如果我搜索所有事件类型,则返回的记录数是正确的。
我手动检查了记录,每个记录都附有一个事件类型1081。
(事件类型与我想要显示的评论相匹配,我只想显示最近的1081条评论)
这是代码
SELECT
o.SiteIdAndName,
o.Id,
r.callid,
o.masterSymptom,
o.subSymptom,
o.received,
o.closed,
r.eventtype,
r.datetime,
r.loggedby,
r.eventcomments,
--o.lastedt,
DATEDIFF(HOUR, received, COALESCE(closed, GETDATE())) AS 'HoursOpen'
FROM
vw_UserView_OpenAndClosed2016 o
LEFT JOIN dbo.tblcallev r ON r.callid = o.id --and r.eventtype = 1081
WHERE
o.SchemeName = 'INDIS'
AND o.SubSymptom = 'Care'
AND Closed is NULL
AND r.datetime = (
SELECT MAX(datetime)
FROM dbo.tblcallevents
WHERE NOT r.eventtype = 1009
AND callid = r.callid
)
Order by
r.eventtype
你可以帮助我吗?
答案 0 :(得分:0)
我认为这可能是非常直接的前言查询,如下面的
nothrow
此处SELECT TOP(1) *--column list here
FROM
vw_UserView_OpenAndClosed2016 o
INNER JOIN dbo.tblcallev r ON r.callid = o.id and r.eventtype = 1081
WHERE o.SchemeName = 'INDIS' AND o.SubSymptom = 'Care' AND Closed is NULL
ORDER BY r.datetime
会根据ORDER BY r.datetime
更新:
r.eventtype = 1081