现在的位置: 首页 > 综合 > 正文

student表生成bj表的sql语句

2013年07月09日 ⁄ 综合 ⁄ 共 576字 ⁄ 字号 评论关闭

insert into bj(bjdh)
select distinct substring(id,1,8) as bjdh
from student
where substring(id,1,1)!='P'
union
select distinct substring(id,1,9) as bjdh
from student
where substring(id,1,1)='P'


insert into bj(bjdh)
select distinct left(id,len(id)-2) as bjdh
from student


insert into bj(bjdh,bjmc)
select distinct left(id,len(id)-2) as bjdh,zymc+right(left(id,len(id)-2),4) as bjmc
from student,zy
where left(id,len(id)-6)=zydh


insert into bj(bjdh,bjmc)
select distinct left(id,len(id)-2) as bjdh,zymc+right(left(id,len(id)-2),4) as bjmc
from student,zy
where substring(id,len(id)-5,2)='07' and left(id,len(id)-6)=zydh

注意:bj表其它的字段应该可以为空

抱歉!评论已关闭.