在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

SQL中怎么实现根据两列信息整合两张表数据

212次阅读
没有评论

共计 2809 个字符,预计需要花费 8 分钟才能阅读完成。

本篇内容介绍了“SQL 中怎么实现根据两列信息整合两张表数据”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让丸趣 TV 小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

两张表数据如下:

–2017 年

idcollegescoreA001 北京大学  670A002 中国人民大学  646A003 清华大学  664A003 清华大学   (定向)
A004 北京交通大学  615A004 北京交通大学   (中外合作办学)
A005 北京工业大学  
A005 北京工业大学   (中外合作办学)

–2018 年

idcollegescoreA001 北京大学  680A002 中国人民大学  662A003 清华大学  671A003 清华大学   (院校特定要求)
A004 北京交通大学  634A004 北京交通大学   (中外合作办学)
A005 北京工业大学  
A005 北京工业大学   (中外合作办学)
A006 北京航空航天大学  640A007 北京理工大学  636A007 北京理工大学   (中外合作办学)
A008 北京科技大学  632Y007 北京理工大学  621

需求,新表四列,id  college,s2017,s2018  两张表整合在一起,根据 id、college

相关语句如下:

-- 创建 2017/2018 表
create table score2017 (id varchar2(10),college varchar2(60),s2017 int);
create table score2018 (id varchar2(10),college varchar2(60),s2018 int);
-- 创建集合表
create table score1718 (id varchar2(10),college varchar2(60),s2017 int,s2018 int);
-- 删除 2017 年表中重复学校和 id
delete from score2017 where replace(college,   ,)= 广西大学 (专业志愿)  -- 5 行
delete from score2017 where replace(college,   ,)= 河北师范大学 (专业志愿)  -- 2 行
-- 插入两张表相同数据  1138 行
insert into score1718 select a.id,replace(a.college,   ,),a.s2017,b.s2018 from score2017 a,score2018 b where replace(a.college,   ,)=replace(b.college,   ,) and a.id=b.id 
select count(college) from score1718; --1138  行重复数据
-- 插入 2017 年表中不相同数据  80 行
insert into score1718 value(id,college,s2017) select a.id,replace(a.college,   ,),a.s2017 from score2017 a where replace(a.college,   ,) not in (select replace(a.college,   ,) from score2017 a,score2018 b where replace(a.college,   ,)=replace(b.college,   ,)) 
-- 插入 2018 年表中不相同数据  134 行
insert into score1718 value(id,college,s2018) select b.id,replace(b.college,   ,),b.s2018 from score2018 b where replace(b.college,   ,) not in (select replace(a.college,   ,) from score2017 a,score2018 b where replace(a.college,   ,)=replace(b.college,   ,))
-- 插入 2018 年表中相同学校不相同 id 数据  8 行
insert into score1718 value(id,college,s2018) select id,college,s2018 from score2018 b where b.college in (select college from score2018 group by college having count(*)   1) and b.id not in(select a.id from score2017 a,score2018 b where replace(a.college,   ,)=replace(b.college,   ,) and a.id=b.id)
-- 对比数据
select count(college) from score2017; --1218 行
select count(college) from score2018; --1280=1138+134+8
-- 集合表中总数据为 1360 行
select count(college) from score1718; --1360=1138+80+134+ 8 行
-- 添加类型列,提取字段
alter table score1718 add (CollegeType varchar2(40));
update score1718 set CollegeType= 普通  where college not like  %(%)%  --982 行
update score1718 set CollegeType=substr(college,instr(college, ()+1,instr(college,) )-instr(college, ()-1) where college like  %(%)%  --378 行
select id,college,CollegeType from score1718;
-- 结果如下所示:id college s2017 s2018 CollegeType
A650 四川外国语大学 582  608 普通
A651 西南财经大学 619  638 普通
A652 西南政法大学 612  627 普通
A652 西南政法大学 (中外合作办学) 599  624 中外合作办学
A653 成都体育学院 540   普通
A655 四川美术学院 549  570 普通
A656 西南民族大学 556  582 普通
A657 贵州大学 586  601 普通
A660 贵州医科大学   普通 

“SQL 中怎么实现根据两列信息整合两张表数据”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注丸趣 TV 网站,丸趣 TV 小编将为大家输出更多高质量的实用文章!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-24发表,共计2809字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 另类国产精品一区二区 | 国产精品久久久视频 | 中文亚洲日韩欧美 | 视频一区视频二区在线观看 | 亚洲欧美日本综合 | 国内精品久久久久久久久久影视 | 欧美成人一区二区三区在线观看 | 日韩av第一页在线播放 | 欧乱色国产精品兔费视频 | 国产乱熟肥女视频网站 | 国产自精品 | 亚洲熟妇无码一区二区三区 | 浮妇高潮喷白浆视频 | 亚洲 欧洲 日韩 综合二区 | 夜色福利久久久久久777777 | 综合成人 | 午夜高清免费在线观看 | 免费一本色道久久一区 | 一本无码中文字幕在线观 | 精品国偷自产在线视频99 | 国产综合成人久久大片91 | 一区不卡视频 | 国模思思 | 四虎影视大全 | 午夜免费福利片观看 | 亚洲日韩av无码一区二区三区 | 免费看无码特级毛片 | 国产亚洲欧美在线人成aaaa | 日韩欧美中文字幕在线播放 | 亚洲毛片视频 | 99热这里只有精品88 | 四虎欧美| 中文字幕丰满伦子无码 | 青青草原伊人网 | 四虎免费永久在线播放 | 午夜片 飘香香影院 | 精品国产女同疯狂摩擦2 | 最新国产三级在线不卡视频 | 国产三级短视频 | 久久免费视频2 | 精品真实国产乱文在线 |