读书人

新手!求一SQL语句

发布时间: 2012-01-24 23:11:54 作者: rapoo

新手求助!求一SQL语句!
表A
F_code F_name F_phone
001 aaa 123
002 bbb 666
003 ccc 999

表B
F_code F_name F_phone
002 bbb 666


表C
F_changcode F_type
001 0
002 1


根据表C里的F_code把表A的记录更新到表B当中(表A与表B结构相同)
当F_type=0 时就根据F_changcode的编号把表A中的记录插入到表B中
当F_type=1时就把表B中的记录删除
请问该怎么做?



[解决办法]
这个结果应该就是表b的内容
select a.* from 表a a inner join 表c c on a.F_code=c.F_changecode where c.F_type=0
[解决办法]
--插入

insert B
select * from A where F_code in
(select distinct F_changcode from C where F_type=0)

[解决办法]
insert into #B
select *
from #A
where F_code in (select F_changeCode from #C where F_type=0)

delete #B
where F_code in (select F_changeCode from #C where F_type=1)

读书人网 >SQL Server

热点推荐