需求概述
数据库结构
表Features
表Features的列: FeatureType | Removable | RemoveTech | 略
表Features_XP2
表Features_XP2的列: FeatureType | volcano | 略
Features_XP2有可能不存在,Features一定存在。
数据
关注FeatureType值为'FEATURE_FLOODPLAINS','FEATURE_OASIS','FEATURE_REEF','FEATURE_GEOTHERMAL_FISSURE'的记录,其它数据不处理。
一个简单的操作
update Features set Removable=1,RemoveTech='TECH_MASS_PRODUCTION' where FeatureType in
('FEATURE_FLOODPLAINS','FEATURE_OASIS','FEATURE_REEF','FEATURE_GEOTHERMAL_FISSURE')
实际需求
在上一节的基础上,判断Features_XP2是否存在,如果存在则不更改FeatureType='FEATURE_FLOODPLAINS'的记录。
实现代码
update Features set Removable=1,RemoveTech='TECH_MASS_PRODUCTION' where FeatureType in
(
select FeatureType from
(select FeatureType from Features where FeatureType='FEATURE_FLOODPLAINS') LEFT OUTER JOIN
( select name from sqlite_master where type='table' and name='Features_XP2')
where name is NULL
UNION
select FeatureType from Features where FeatureType in ('FEATURE_OASIS','FEATURE_REEF','FEATURE_GEOTHERMAL_FISSURE')
);
应用
这是一个游戏插件(MOD)中的代码,作者是本人。