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

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

233次阅读
没有评论

共计 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字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 亚洲精品久久夜色撩人男男小说 | 四虎国产成人免费观看 | 国内精品视频九九九九 | 亚洲精品国产电影 | 国产xxx在线 | 在线视频你懂得 | 国产精品国产午夜免费福利看 | 欧美大尺度免费一级特黄 | 激情宗合 | 国产亚洲欧美一区 | 成人免费视频网站www | 国产三级在线视频观看 | 波多野结衣高潮av在线播放 | 在线99热| 欧美久久久久久 | 国产欧美日韩在线一区二区不卡 | 无码人妻精品一区二区在线视频 | 久久99青青精品免费观看 | 热久久这里只有精品 | 在线va无码中文字幕 | 亚洲精品一区二区三区蜜臀 | 草久免费视频 | 国精产品一二二区视频 | 免费一级欧美毛片 | 亚洲高清在线播放 | 无码喷潮a片无码高潮 | 国产真实乱对白精彩久久老熟妇女 | 亚洲av成人www永久无码精品 | 亚洲av无码欧洲av无码网站 | 久久精品国产清自在天天线 | 精品综合久久久久久蜜月 | 午夜视频在线观看免费视频 | 国产黄大片在线观看 | 国产亚洲精品久久久久秋 | 日韩免费片 | 午夜理论无码片在线观看免费 | 色喜国模李晴超大尺度 | 国产精品卡一卡二卡三 | 免费国产一区二区在免费观看 | 四虎在线视频免费观看视频 | 噜妇插内射精品 |