热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

php查题,php查询45题

表格代码createtablestudent(snovarchar(20)primarykey,snamevarchar(20)notnull,ssexvarchar(20)not

表格代码

cdec0645add3fc3c328197dda5c76203.png

81178cc93a2a3bb5048d90d76e7ec935.png

create tablestudent

(

snovarchar(20) primary key,

snamevarchar(20) not null,

ssexvarchar(20) not null,

sbirthdaydatetime,

classvarchar(20)

)

;create tableteacher

(

tnovarchar(20) primary key,

tnamevarchar(20) not null,

tsexvarchar(20) not null,

tbirthdaydatetime,

profvarchar(20),

departvarchar(20) not null)

;create tablecourse

(

cnovarchar(20) primary key,

cnamevarchar(20) not null,

tnovarchar(20) not null,foreign key(tno) referencesteacher(tno)

)

;create tablescore

(

snovarchar(20) not null,

cnovarchar(20) not null,

degreedecimal(4,1),foreign key(sno) referencesstudent(sno),foreign key(cno) referencescourse(cno),primary key(sno,cno)

)

;insert into student values(‘108‘,‘曾华‘,‘男‘,‘1977-09-01‘,‘95033‘);insert into student values(‘105‘,‘匡明‘,‘男‘,‘1975-10-02‘,‘95031‘);insert into student values(‘107‘,‘王丽‘,‘女‘,‘1976-01-23‘,‘95033‘);insert into student values(‘101‘,‘李军‘,‘男‘,‘1976-02-20‘,‘95033‘);insert into student values(‘109‘,‘王芳‘,‘女‘,‘1975-02-10‘,‘95031‘);insert into student values(‘103‘,‘陆君‘,‘男‘,‘1974-06-03‘,‘95031‘);insert into teacher values(‘804‘,‘李诚‘,‘男‘,‘1958-12-02‘,‘副教授‘,‘计算机系‘);insert into teacher values(‘856‘,‘张旭‘,‘男‘,‘1969-03-12‘,‘讲师‘,‘电子工程系‘);insert into teacher values(‘825‘,‘王萍‘,‘女‘,‘1972-05-05‘,‘助教‘,‘计算机系‘);insert into teacher values(‘831‘,‘刘冰‘,‘女‘,‘1977-08-14‘,‘助教‘,‘电子工程系‘);insert into course values(‘3-105‘,‘计算机导论‘,‘825‘);insert into course values(‘3-245‘,‘操作系统‘,‘804‘);insert into course values(‘6-166‘,‘数字电路‘,‘856‘);insert into course values(‘9-888‘,‘高等数学‘,‘831‘);insert into score values(‘103‘,‘3-245‘,‘86‘);insert into score values(‘105‘,‘3-245‘,‘75‘);insert into score values(‘109‘,‘3-245‘,‘68‘);insert into score values(‘103‘,‘3-105‘,‘92‘);insert into score values(‘105‘,‘3-105‘,‘88‘);insert into score values(‘109‘,‘3-105‘,‘76‘);insert into score values(‘101‘,‘3-105‘,‘64‘);insert into score values(‘107‘,‘3-105‘,‘91‘);insert into score values(‘108‘,‘3-105‘,‘78‘);insert into score values(‘101‘,‘6-166‘,‘85‘);insert into score values(‘107‘,‘6-166‘,‘79‘);insert into score values(‘108‘,‘6-166‘,‘81‘);

View Code

题目答案

1.select sname,ssex,class from student

2.select distinct depart from teacher

3.select * from student

4.select * from score where degree>60 and degree<80

5.select * from score where degree in(85,86,88)

6.select * from student where class&#61;‘95031‘ or ssex&#61;‘女‘

7.select * from student order by class desc

8.select * from score order by cno asc,degree desc

9.select * from student where class&#61;‘95031‘

10.select * from score order by degree desc

11.我的方法&#xff1a;select avg(degree) from score where cno&#61;‘3-245‘

select avg(degree) from score where cno&#61;‘3-105‘

select avg(degree) from score where cno&#61;‘6-166‘

答案&#xff1a;select Cno,avg(Degree) from Score group by Cno

12.这个题不会

答案&#xff1a;select avg(Degree) from Score where Cno in (select Cno from Score group by Cno having count(*)>5) and Cno like ‘3%‘ group by Cno

13.select sno from score where degree>70 and degree<90

14.select sname,cno,degree from score join student on student.sno&#61;score.sno

15.select sno,cname,degree from score join course on course.cno&#61;score.cno

16.这个题做错了

我的答案&#xff1a;select sname,cname,degree from score join student,course on(student.sno&#61;score.sno and course.cno&#61;score.cno)

正确答案&#xff1a;select Sname,Cname,Degree from Score join Student on Student.Sno &#61; Score.Sno join Course on Score.Cno &#61; Course.Cno

不能写在一起

17.select avg(degree) from score where sno in(select sno from student where class&#61;‘95033‘)

18.这个题写不出

答案&#xff1a;select Sno,Cno,rank from Score join grade on Score.Degree between low and upp

19.select * from score where cno &#61;‘3-105‘ and degree>(select degree from score where sno &#61; ‘109‘ and cno &#61; ‘3-105‘)

若果没写后面的cno &#61; ‘3-105‘ 软件就会崩溃 不知道为什么 试了好几次 0v0

20.这题只会写前半部分 OTZ

答案&#xff1a;理解1

select * from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ) and Degree not in (select max(Degree) from Score b where b.Cno &#61; a.Cno)

理解2

select * from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ) and Degree not in (select max(Degree) from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ))

21.弄不懂和19题有啥区别 理解不能

答案&#xff1a;select * from Score where Degree >(select Degree from Score where Sno &#61; ‘109‘ and Cno &#61; ‘3-105‘)

22.还是写不出...

答案&#xff1a;select Sno,Sname,Sbirthday from Student where YEAR(Sbirthday) &#61; (select YEAR(Sbirthday) from Student where Sno &#61; ‘108‘)

23.关联了3个表 想的出来 但写不出来

答案&#xff1a;select * from Score where Cno in(select Cno from Course where Tno &#61;(select Tno from Teacher where Tname&#61;‘张旭‘))

24.select tname from teacher where tno in(select tno from course where cno in(select cno from score group by cno having count(*) > 5))

25.select * from Student where Class in(‘95031‘,‘95033‘)

突然又变简单了

26.select distinct Cno from Score where Degree > 85

27.select * from Score where Cno in(select Cno from Course where Tno in(select Tno from Teacher where depart &#61; ‘计算机系‘))

28.依旧写不出...

答案&#xff1a;select Tname,prof from Teacher where prof not in(select prof from Teacher where depart &#61; ‘计算机系‘ and prof in(select prof from Teacher where depart&#61;‘电子工程系‘ ))

select prof from Teacher where depart &#61; ‘计算机系‘ and prof not in(select prof from Teacher where depart&#61;‘电子工程系‘ ) union

select prof from Teacher where depart &#61; ‘电子工程系‘ and prof not in(select prof from Teacher where depart&#61;‘计算机系‘ )

29.一脸懵b中

答案&#xff1a;select * from Score where Cno&#61;‘3-105‘ and Degree>any(select Degree from Score where Cno &#61;‘3-245‘) order by Degree desc

30.select * from score where cno&#61;‘3-105‘ and degree>all(select degree from score where cno &#61;‘3-245‘)

31.select sname,ssex,sbirthday from student

union

select tname,tsex,tbirthday from teacher

32.select sname,ssex,sbirthday from student where ssex&#61;‘女‘

union

select tname,tsex,tbirthday from teacher where tsex&#61;‘女‘

33.select * from score a where degree

34.我的答案&#xff1a;select tname,depart from teacher

答案&#xff1a;select Tname,depart from Teacher where Tno in (select Tno from Course )

结果是一样的

35.这个题脑子直接想不明白...

答案&#xff1a;select Tname,depart from Teacher where Tno in(select Tno from Course where Cno not in(select Cno from Score))

36.select class from student where ssex&#61;‘男‘ group by class having count(*)>1

37.select * from student where sno not in(select sno from student where sname like ‘王%‘)

38.select Sname,YEAR(now())-YEAR(Sbirthday) from Student

不知道为什么我写的运行不出来 我没写year

39.select max(sbirthday) from student

select min(sbirthday) from student

40.select * from student order by class desc,sbirthday

41.脑子要炸了

答案&#xff1a;select * from Teacher join Course on Teacher.Tno &#61; Course.Tno where Teacher.Tsex&#61;‘男‘

42.select * from score where degree &#61; (select max(degree) from score )

43.select sname from student where ssex &#61; (select ssex from student where sname&#61;‘李军‘)

44.加了个条件就弄不出来了...

答案&#xff1a;select Sname from Student where Ssex &#61; (select Ssex from Student where Sname&#61;‘李军‘) and Class&#61;(select Class from Student where Sname &#61; ‘李军‘)

45.最后一题依旧写不出来

答案&#xff1a;select * from Score where Sno in(select Sno from Student where Ssex&#61;‘男‘) and Cno in(select Cno from Course where Cname&#61;‘计算机导论‘)

做完这45道题感觉脑子变得和浆糊一样   有三分之一写不出来的   甚至有的看答案都弄不明白不过感觉思路学到不少   就是高级查询一旦到了3层、4层就开始糊迷了   很多时候想

得到却写不出     看来还是too young too simple 还是缺练

另外感觉程序不能马虎啊   一点点问题  甚至一个分号  就会导致崩盘    要细心啊

原文&#xff1a;http://www.cnblogs.com/bilibiliganbei/p/5536161.html



推荐阅读
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 模板引擎StringTemplate的使用方法和特点
    本文介绍了模板引擎StringTemplate的使用方法和特点,包括强制Model和View的分离、Lazy-Evaluation、Recursive enable等。同时,还介绍了StringTemplate语法中的属性和普通字符的使用方法,并提供了向模板填充属性的示例代码。 ... [详细]
  • 本文主要复习了数据库的一些知识点,包括环境变量设置、表之间的引用关系等。同时介绍了一些常用的数据库命令及其使用方法,如创建数据库、查看已存在的数据库、切换数据库、创建表等操作。通过本文的学习,可以加深对数据库的理解和应用能力。 ... [详细]
  • 本文介绍了使用哈夫曼树实现文件压缩和解压的方法。首先对数据结构课程设计中的代码进行了分析,包括使用时间调用、常量定义和统计文件中各个字符时相关的结构体。然后讨论了哈夫曼树的实现原理和算法。最后介绍了文件压缩和解压的具体步骤,包括字符统计、构建哈夫曼树、生成编码表、编码和解码过程。通过实例演示了文件压缩和解压的效果。本文的内容对于理解哈夫曼树的实现原理和应用具有一定的参考价值。 ... [详细]
  • 合并列值-合并为一列问题需求:createtabletab(Aint,Bint,Cint)inserttabselect1,2,3unionallsel ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • C# 7.0 新特性:基于Tuple的“多”返回值方法
    本文介绍了C# 7.0中基于Tuple的“多”返回值方法的使用。通过对C# 6.0及更早版本的做法进行回顾,提出了问题:如何使一个方法可返回多个返回值。然后详细介绍了C# 7.0中使用Tuple的写法,并给出了示例代码。最后,总结了该新特性的优点。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
  • 这篇文章主要介绍了Python拼接字符串的七种方式,包括使用%、format()、join()、f-string等方法。每种方法都有其特点和限制,通过本文的介绍可以帮助读者更好地理解和运用字符串拼接的技巧。 ... [详细]
author-avatar
AdrianFree覀
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有