create table table1
(number int, age int)
insert table1
select 100,     20
union all
select 101,     45
union all
select 103,     60create table table2
(number int,   age int)
insert table2
select 100,      22
union all
select 102,      30
union all
select 103,      35update table1
set age=table2.age
from table2
where table1.number=table2.numberselect * into table3 from table1select * from table3number      age         
----------- ----------- 
100         22
101         45
103         35(所影响的行数为 3 行)

解决方案 »

  1.   

    declare @table1 table(number int,age int)
    insert into @table1
    select 100,20 union
    select 101,45 union
    select 103,60declare @table2 table(number int,age int)
    insert into @table2
    select 100,22 union
    select 102,30 union
    select 103,35--取age为成年(18~59)的记录
    select number,max(age)age from (
    select * from @table1
    union
    select * from @table2
    )a
    where age between 18 and 59 and exists(select number from @table1 where number=a.number)
    group by number-------结果-----
    number      age         
    ----------- ----------- 
    100         22
    101         45
    103         35(所影响的行数为 3 行)
      

  2.   

    SELECT A.NUMBER, CASE A.AGE >= B.AGE THEN A.AGE ELSE B.AGE END AGE
    FROM A, B
    WHERE A.NUMBER = B.NUMBER
      

  3.   

    弄错了
    SELECT A.NUMBER, 
    CASE WHEN A.AGE > B.AGE THEN A.AGE ELSE B.AGE END AGE
    FROM TABLE1 A, TABLE2 B
    WHERE A.NUMBER = B.NUMBER