db1.tb1:
tm w m1 m2
030201010204 170 1500 1300
030102040507 350 1400 0900
........................................................
db2.tb2:
tm v
030201020304 1500
030201010204 3500
030405040201 2500
030900050404 6000
030204050604 0900
............................................................
现在要向db2.tb2中加入一列 m 生成tb3
tm v m
030201020304 1500 1400
............................................................
其中当 90< db1.tb1.w <270 时 tb3.m=db1.tb1.m1
其他情况 tb3.m=db1.tb1.m2
条件是:
db1.tb1.tm=db2.tb2.tm
db2.tb2.v<=1500说明:db1:数据库 tb1:表
tm w m1 m2
030201010204 170 1500 1300
030102040507 350 1400 0900
........................................................
db2.tb2:
tm v
030201020304 1500
030201010204 3500
030405040201 2500
030900050404 6000
030204050604 0900
............................................................
现在要向db2.tb2中加入一列 m 生成tb3
tm v m
030201020304 1500 1400
............................................................
其中当 90< db1.tb1.w <270 时 tb3.m=db1.tb1.m1
其他情况 tb3.m=db1.tb1.m2
条件是:
db1.tb1.tm=db2.tb2.tm
db2.tb2.v<=1500说明:db1:数据库 tb1:表
select A.tm,A.v,(case when B.w>90 and B.w<270 then B.m1 else B.m2)
from db2.tb2 A,db1.tb1 B
where B.tm=A.tm and A.v<=1500
select A.tm,A.v,(case when B.w>90 and B.w<270 then B.m1 else B.m2 end)
from db2.tb2 A,db1.tb1 B
where B.tm=A.tm and A.v<=1500