SQL语句修改,如何将下面的insert语句改为update语句。
insert语句:insertintoR_Countselect'News'astype,typeasxtype,sum(casewhenflag=0then1else0...
insert语句:
insert into R_Count
select 'News' as type,type as xtype,
sum(case when flag=0 then 1 else 0 end) as "error",
sum(case when flag=1 then 1 else 0 end) as "normal",
sum(case when flag=2 then 1 else 0 end) as "unknown",
GETDATE() as "execTime"
from R_NewsUser_Netbar
group by type
insert结果: 展开
insert into R_Count
select 'News' as type,type as xtype,
sum(case when flag=0 then 1 else 0 end) as "error",
sum(case when flag=1 then 1 else 0 end) as "normal",
sum(case when flag=2 then 1 else 0 end) as "unknown",
GETDATE() as "execTime"
from R_NewsUser_Netbar
group by type
insert结果: 展开
2个回答
展开全部
-- for M$SQL
update a set
error = b.error
, normal = b.normal
, unknown = b.unknown
, exectime = getdate()
from r_count as a
join (
select type,
sum(case when flag=0 then 1 else 0 end) as "error",
sum(case when flag=1 then 1 else 0 end) as "normal",
sum(case when flag=2 then 1 else 0 end) as "unknown",
from R_NewsUser_Netbar
group by type
) as b on 1=1
and 'News' = a.type
and b.type = a.xtype
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询