热门标签 | 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



推荐阅读
  • 本文探讨了如何在PHP与MySQL环境中实现高效的分页查询,包括基本的分页实现、性能优化技巧以及高级的分页策略。 ... [详细]
  • 本文探讨了如何使用Scrapy框架构建高效的数据采集系统,以及如何通过异步处理技术提升数据存储的效率。同时,文章还介绍了针对不同网站采用的不同采集策略。 ... [详细]
  • 本文详细介绍了Oracle 11g中的创建表空间的方法,以及如何设置客户端和服务端的基本配置,包括用户管理、环境变量配置等。 ... [详细]
  • 在使用mybatis进行mapper.xml测试的时候发生必须为元素类型“mapper”声明属性“namespace”的错误项目目录结构UserMapper和UserMappe ... [详细]
  • 本文详细介绍如何在SSM(Spring + Spring MVC + MyBatis)框架中实现分页功能。包括分页的基本概念、数据准备、前端分页栏的设计与实现、后端分页逻辑的编写以及最终的测试步骤。 ... [详细]
  • 笔记说明重学前端是程劭非(winter)【前手机淘宝前端负责人】在极客时间开的一个专栏,每天10分钟,重构你的前端知识体系& ... [详细]
  • 【MySQL】frm文件解析
    官网说明:http:dev.mysql.comdocinternalsenfrm-file-format.htmlfrm是MySQL表结构定义文件,通常frm文件是不会损坏的,但是如果 ... [详细]
  • 视觉Transformer综述
    本文综述了视觉Transformer在计算机视觉领域的应用,从原始Transformer出发,详细介绍了其在图像分类、目标检测和图像分割等任务中的最新进展。文章不仅涵盖了基础的Transformer架构,还深入探讨了各类增强版Transformer模型的设计思路和技术细节。 ... [详细]
  • binlog2sql,你该知道的数据恢复工具
    binlog2sql,你该知道的数据恢复工具 ... [详细]
  • Maven + Spring + MyBatis + MySQL 环境搭建与实例解析
    本文详细介绍如何使用MySQL数据库进行环境搭建,包括创建数据库表并插入示例数据。随后,逐步指导如何配置Maven项目,整合Spring框架与MyBatis,实现高效的数据访问。 ... [详细]
  • 本文详细介绍了JQuery Mobile框架中特有的事件和方法,帮助开发者更好地理解和应用这些特性,提升移动Web开发的效率。 ... [详细]
  • 本文详细介绍了PostgreSQL与MySQL在SQL语法上的主要区别,包括如何使用COALESCE替代IFNULL、金额格式化的方法、别名处理以及日期处理等关键点。 ... [详细]
  • 汇总了2023年7月7日最新的网络安全新闻和技术更新,包括最新的漏洞披露、工具发布及安全事件。 ... [详细]
  • 本文提供了一个关于AC自动机(Aho-Corasick Algorithm)的详细解析与实现方法,特别针对P3796题目进行了深入探讨。文章不仅涵盖了AC自动机的基本概念,还重点讲解了如何通过构建失败指针(fail pointer)来提高字符串匹配效率。 ... [详细]
  • SSE图像算法优化系列三:超高速导向滤波实现过程纪要(欢迎挑战)
    自从何凯明提出导向滤波后,因为其算法的简单性和有效性,该算法得到了广泛的应用,以至于新版的matlab都将其作为标准自带的函数之一了&#x ... [详细]
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社区 版权所有