seledt * from region;
---------
region_code region_name population
0451 哈尔滨
0452 齐齐哈尔
0454 双鸭山
-------
select * from HLJ_population ;region_code population region_type
0451 300000 a
0452 2000 b
0454
-------------
update region a set population=( select population b from HLJ_population where a.region_code=b.region_code and b.region_type='a' );
update region a set population=( select population b from HLJ_population where a.region_code=b.region_code and b.region_type='b' );
----------
经常希望能够通过以上结果最终出现:
region_code region_name population
0451 哈尔滨 300000
0452 齐齐哈尔 2000
0454 双鸭山
---但实际结果显示region_code region_name population
0451 哈尔滨
0452 齐齐哈尔 2000
0454 双鸭山
这是因为在执行第二个update语句的时候,将0451代入子查询得到null,然后update语句就将300000 改为 null
---------
region_code region_name population
0451 哈尔滨
0452 齐齐哈尔
0454 双鸭山
-------
select * from HLJ_population ;region_code population region_type
0451 300000 a
0452 2000 b
0454
-------------
update region a set population=( select population b from HLJ_population where a.region_code=b.region_code and b.region_type='a' );
update region a set population=( select population b from HLJ_population where a.region_code=b.region_code and b.region_type='b' );
----------
经常希望能够通过以上结果最终出现:
region_code region_name population
0451 哈尔滨 300000
0452 齐齐哈尔 2000
0454 双鸭山
---但实际结果显示region_code region_name population
0451 哈尔滨
0452 齐齐哈尔 2000
0454 双鸭山
这是因为在执行第二个update语句的时候,将0451代入子查询得到null,然后update语句就将300000 改为 null
set population = (select population from HLJ_population where HLJ_population.region_code = region.region_code)
where region_code in (select region_code from HLJ_population)