哈工大软件学院数据库实验1
发布日期:2021-07-24 21:57:39
浏览次数:11
分类:技术文章
本文共 3540 字,大约阅读时间需要 11 分钟。
前言
这个实验很简单,我先讲下大致步骤,然后再解释详细点,再附上实验解答
实验内容
这次实验就是说白了,把外部的txt文件通过sqlite等软件导入到一个数据库里面去,这个数据库就是db3后缀的那个文件
然后不是导入进去了吗?导入进去之后就对数据库里面的数据进行一系列的操作,这就达到了实验的目的实验难点
.初学者不会使用软件,不知道该怎么操作
.不理解相关信息含义,无法写出有质量的代码相关难点剖析:(利用sqlite)
创建数据库用 .open seen.db3 //seen.db3是自己改的 创建表用create table(…这里面输入各种键值,用来接数据); .separator “,” 这个里面的逗号是定义txt文件里面的那个分隔符,利用这个分隔符读取文件 关于导入导出的技巧:1.txt文件千万不能有多余的空格2.导入时txt文件里面的分割符要和导入的相一致3.import语句不要分号4.导入的时候是会重复导入的,前面导入的后面还会有5.字符串存储相当严格,连空格都会存储进去
实验解答
我看了几年的实验,似乎都是那50道题,认真学习的同学会发现这些都在PPT上能够找到,如果不认真的就上网找吧,但愿你们能够找到这里来,给我博客增添点人气~~~
所以我就直接附上那50道题的代码了,每个都是经过我测试好的。如果其中有问题就找我来问吧,我肯定会帮助你解决的11,select sID,sName,GPA from Student where GPA>3.6; 12,select sID,sName from Student where GPA>3.6; 13,select sName,cName from Student,Apply where Student.sID = Apply.sID; 14,select distinct sName,cName from Student,Apply where Student.sID = Apply.sID;(从上条我们就可以看出,去除重复元组是有多强) 15,select sName,GPA,decision from Student,Apply where Student.sID=Apply.sID and cName='Stanford' and major='CS' and sizeHS<1000; 16,select distinct College.cName from College,Apply where College.cName=Apply.cName and major='CS' and enrollment>20000; 17,select sName,College.cName,GPA,state,enrollment from Apply,Student,College where Apply.sID = Student.sID and Apply.cName = College.cName order by GPA desc; 在满足上述条件下想让次要条件按enrollment降序就可以在后面加一句enrollment desc; 18,参照17附加 19,select sID,major from Apply where major like '%bio%'; 20,select * from College,Student; 21,...略 22,select s1.sName,s2.sName from Student s1,Student s2 where s1.sID!=s2.sID and s1.GPA=s2.GPA;(去除重复元素似乎不管用) ----------有点问题 22,23 同 24,select cName from College union all select sName from Student;(含重复) 不含重复版本: select distinct cName from College union all select distinct sName from Student; 25,select distinct cName as name from College union all select distinct sName as name from Student order by name; 26,25已经完成 27,select sID from Apply where major=='CS' intersect select sID from Apply where major = 'EE'; 28,select sID from Apply where major=='CS' except select sID from Apply where major = 'EE'; 29,select sName,sID from Student where sID in (select sID from Apply where major='CS'); 30,select distinct sName from Student,Apply where Student.sID= Apply.sID and major='CS'; 或者:select distinct sName from Student where sID in(select sID from Apply where major='CS'); 31,select distinct sID from Apply where sID in (select sID from Apply where major = 'CS') and sID not in (select sID from Apply where major = 'EE'); 32,select cName from College s1 where not exists (select * from College s2 where s1.enrollments2.GPA ) and major='CS'; 41,select avg(GPA) from Student natural join Apply where major='CS'; 42,select count(*) from College where enrollment>15000; 43,select count(*) from Apply where cName='Cornell' and sID in (select distinct sID from Apply); //这个有问题,牛逼牛逼 44,select CS.avgGPA-NonCS.avgGPA from (select avg(GPA) as avgGPA from Student natural join Apply where major='CS') as CS,(select avg(GPA) as avgGPA from Student where sID not in(select sID from Apply where major='CS')) as NonCS; 45,select cName,count(*) from Apply group by cName; 46,select state,sum(enrollment) from College group by state; 47,select cName,major,max(GPA),min(GPA) from Student natural join Apply group by cName,major; //group by 可以循环使用 48,select sID,sName,count(*) from Apply natural join Student group by Apply.sID; 50,select cName from Apply group by cName having count(*)<5;
转载地址:https://blog.csdn.net/qq_23100787/article/details/48328829 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月14日 12时21分23秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
基于VMware安装CentOs7的镜像
2019-04-27
PL/SQL数据库管理工具的使用
2019-04-27
带你玩转属于自己的spring-boot-starter系列(一)
2019-04-27
带你玩转属于自己自己的spring-boot-starter系列(二)
2019-04-27
带你玩转属于自己的spring-boot-starter系列(三)
2019-04-27
基于SnowFlake算法如何让分库分表中不同的ID落在同一个库的算法的实现
2019-04-27
Linux文件管理参考
2019-04-27
FTP文件管理项目(本地云)项目日报(一)
2019-04-27
FTP文件管理项目(本地云)项目日报(二)
2019-04-27
FTP文件管理项目(本地云)项目日报(三)
2019-04-27
FTP文件管理项目(本地云)项目日报(四)
2019-04-27
【C++】勉强能看的线程池详解
2019-04-27
FTP文件管理项目(本地云)项目日报(七)
2019-04-27
FTP文件管理项目(本地云)项目日报(八)
2019-04-27
【Linux】血泪教训 -- 动态链接库配置方法
2019-04-27
FTP文件管理项目(本地云)项目日报(九)
2019-04-27
以练代学设计模式 -- FTP文件管理项目
2019-04-27