Sql 我有一个表,其中有几列我想用带有op_日期(2015年1月4日)的费率替换带有op_日期(2014年1月4日)的费率
将具有运营日期(2015年1月4日)的费率替换为具有运营日期(2014年1月4日)的费率 表格记录Sql 我有一个表,其中有几列我想用带有op_日期(2015年1月4日)的费率替换带有op_日期(2014年1月4日)的费率,sql,Sql,将具有运营日期(2015年1月4日)的费率替换为具有运营日期(2014年1月4日)的费率 表格记录 如果我理解了您的问题,那么答案是:不可能在一个查询中完成这项工作,您需要一个pl/sql脚本 declare tmp1 number; tmp2 number; begin select rate into tmp1 from yourtable where op_date = to_date (040115,'ddmmrr') and code='cs002'; select
如果我理解了您的问题,那么答案是:不可能在一个查询中完成这项工作,您需要一个pl/sql脚本
declare
tmp1 number;
tmp2 number;
begin
select rate into tmp1 from yourtable where op_date = to_date (040115,'ddmmrr') and code='cs002';
select rate into tmp2 from yourtable where op_date = to_date (040114,'ddmmrr') and code='cs002';
update tablename set rate=tmp1 where op_date = to_date (040114,'ddmmrr') and code='cs002';
update tablename set rate=tmp2 where op_date = to_date (040115,'ddmmrr') and code='cs002';
commit;
end;
/
请注意,如果速率值与日期和代码不唯一,则此脚本将给出错误您的实际数据和预期输出是什么?您使用的是哪种DBMS?示例:代码-El001,日期-2015-04-01的速率为0我想用代码-El001替换此速率值,日期-2014-04-01费率15.33,但代码很多,费率也不同。为了便于理解,公司希望上一年的费率适用于本年,那个么sql查询是什么呢