ORACLE中update今天的数据,把昨天的清空了
我的语句如下,想把查询出来的昨天26号数量(mycount)更新在今天的时间为27号的events列,匹配字段为(eventstype_sub,datetime),今天的...
我的语句如下,想把查询出来的昨天26号数量(mycount)更新在今天的时间为27号的events列,匹配字段为(eventstype_sub,datetime),今天的数据是插进去了,但把昨天的清空了?,这是什么情况,哪里出错了?下面是我的语句:
update table s set events=
nvl((
select p.mycount from
(select t.name,count(t.name)as mycount from netmonitor_exception_event t
where t.storetime>=trunc(sysdate)-1
and t.storetime<(trunc(sysdate)
group by t.name)p
where p.name=s.eventstype_sub
and s.datetime=trunc(sysdate)
),0) 展开
update table s set events=
nvl((
select p.mycount from
(select t.name,count(t.name)as mycount from netmonitor_exception_event t
where t.storetime>=trunc(sysdate)-1
and t.storetime<(trunc(sysdate)
group by t.name)p
where p.name=s.eventstype_sub
and s.datetime=trunc(sysdate)
),0) 展开
展开全部
update table s set events=
nvl((
select p.mycount from
(select t.name,count(t.name)as mycount from netmonitor_exception_event t
where t.storetime>=trunc(sysdate)-1
and t.storetime<(trunc(sysdate)
group by t.name)p
where p.name=s.eventstype_sub
and s.datetime=trunc(sysdate) --这里有问题吧?
),0)
如果是s.datetime=trunc(sysdate) 不应该放到where条件里吗?
如下:
update table s set events=
nvl((
select p.mycount from
(select t.name,count(t.name)as mycount from netmonitor_exception_event t
where t.storetime>=trunc(sysdate)-1
and t.storetime<(trunc(sysdate)
group by t.name)p
where p.name=s.eventstype_sub
),0)
where s.datetime=trunc(sysdate)
nvl((
select p.mycount from
(select t.name,count(t.name)as mycount from netmonitor_exception_event t
where t.storetime>=trunc(sysdate)-1
and t.storetime<(trunc(sysdate)
group by t.name)p
where p.name=s.eventstype_sub
and s.datetime=trunc(sysdate) --这里有问题吧?
),0)
如果是s.datetime=trunc(sysdate) 不应该放到where条件里吗?
如下:
update table s set events=
nvl((
select p.mycount from
(select t.name,count(t.name)as mycount from netmonitor_exception_event t
where t.storetime>=trunc(sysdate)-1
and t.storetime<(trunc(sysdate)
group by t.name)p
where p.name=s.eventstype_sub
),0)
where s.datetime=trunc(sysdate)
追问
确实是要将s.datetime=trunc(sysdate) 放在后面,那where p.name=s.eventstype_sub这个要不要和s.datetime=trunc(sysdate)一起放在后面?
追答
这个不用放,最后的where条件只能放s表的过滤。。。
而where p.name=s.eventstype_sub 这个实际是个关联条件。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询