您好,我正在尝试获取查询中的最后一个wostatus.changedate,并且我具有针对Maximo(CMMS)的以下代码:
workorder.istask = 0 and (workorder.worktype = 'CM' or workorder.worktype = 'CP' or workorder.worktype = 'PM') and (workorder.woclass = 'WORKORDER' or workorder.woclass = 'ACTIVITY')
and (workorder.schedfinish >= dateadd(week, datediff(week, 0, getdate())+0, 0)
and workorder.schedfinish <= dateadd(week, datediff(week, 0, getdate())+1, 0)
and workorder.schedstart >= dateadd(week, datediff(week, 0, getdate())+0, 0)
and workorder.schedstart <= dateadd(week, datediff(week, 0, getdate())+1, 0))
and workorder.historyflag = 0 and workorder.siteid = 'CORE' and workorder.status != 'WPLAN' and workorder.wonum in
(select wostatus.wonum from wostatus where (wostatus.status = 'APPR') and wostatus.changeby in ('x', 'xx', 'xxx', 'xxxx' ) and wostatus.changedate >= dateadd(week, datediff(week, 7, getdate()), 2) and wostatus.changedate < dateadd(week, datediff(week, 0, getdate()), 3))
下面是我需要过滤最新日期的代码部分,尽管我并没有成功获取最新日期,但我需要的是这样的
(select wostatus.wonum from wostatus where (wostatus.status = 'APPR') and wostatus.changeby in ('x', 'xx', 'xxx', 'xxxx' ) and wostatus.changedate >= dateadd(week, datediff(week, 7, getdate()), 2) and wostatus.changedate = MOST RECENT DATE)
整个查询都在查看特定工作类型的工作订单,这些工作订单是在当前一周内安排的,他们的状态最后一次由特定人员更改为APPR,并且此更改是在特定时间发生的。我希望看到这些人在wostatus.changeby中最后一次修改wostatus.status ='APP'。
此刻,我的查询仅查看特定时间的批准日期,而我希望它是最近批准的日期。
我尝试在查询中加入Max(wostatus.changedate),但未成功。
这可能吗?
谢谢。
答案 0 :(得分:0)
我不确定您到底需要什么,但是请在最后一个细分中尝试一下(加上所有的更改日期和日期过滤器)
select wonum from maximo.wostatus where status = 'APPR' and CHANGEDATE in
(select max(CHANGEDATE) from maximo.wostatus where status = 'APPR'
group by wonum)
这将为您提供最近批准的工作单的过滤器。 如果您更需要某些用户的最新消息,请尝试
select wonum from maximo.wostatus where status = 'APPR' and CHANGEDATE in
(select max(CHANGEDATE) from maximo.wostatus where status = 'APPR'
group by changeby)