当前位置:   article > 正文

数据库--简单查询_mysql查询年龄在18到20之间的女学生的学号和姓名

mysql查询年龄在18到20之间的女学生的学号和姓名

简单查询要求如下:

(1)查询全体学生的学号和姓名。

(2)查询全体学生的姓名和出生年份。

(3)显示student表中的所有行和列。

(4)学分为2的课程名。

(5)查询名族为汉族的学生姓名和年龄。

(6)查询考试成绩中有不及格科目的学生的学号。

(7)查询年龄在18-20岁(包括18岁和20岁)之间的学生的姓名和年龄。

(8)查询所有女学生的姓名和出生年份。

(9)查询通信系和计算机系学生的姓名和性别。

(10)查询既不是通信系也不是计算机系的学生的姓名和性别。

(11)查询所有姓张的学生的姓名、学号和性别。

(12)查询全名为两个汉字的学生的姓名。

(13)查询所有不姓张的学生的姓名。

(14)查询名字中第2个字为“无”字的学生的姓名和学号。

(15)查询缺考学生的学号和课程号。

(16)查询所有有成绩的学生的学号和课程号。

(17)查询选修了课程的学生的学号并去除重复行。

提供表格信息如下:

student表

sno

sname

ssex

sage

snat

sdept

S1

赵无言

18

汉族

计算机系

S2

蒋洪

19

回族

通信系

S3

汪艳

18

汉族

自动化

S4

张拟

18

汉族

通信系

S5

孙瑶

19

汉族

电子系

S6

张军军

20

回族

计算机系

course表

cno

cname

credit

001

C语言程序设计

2

002

高数

3

003

大学英语

2

004

计算机网络

3

005

数据库原理

2

 sc表

sno

cno

grade

S1

001

80

S1

003

75

S2

002

54

主要运行代码如下:

  1. create database JXGL1
  2. on
  3. (name=JXGL,
  4. filename='D:\sql\JXGL1.mdf',//选择自己的文件保存位置
  5. size=10MB,
  6. maxsize=30MB,
  7. filegrowth=5MB)
  8. log on
  9. (name=xxgl_log,
  10. filename='D:\sql\JXGL1_log.ldf',
  11. size=4MB,
  12. maxsize=10MB,
  13. filegrowth=2MB)
  14. use JXGL1
  15. go
  16. create table S(sno char(12)primary key,
  17. sname char(10),
  18. sex char(2),
  19. age tinyint,
  20. sdept nchar(20)
  21. )
  22. create table C
  23. (cno char(3)primary key,
  24. cname nchar(20),
  25. Tname varchar(20),
  26. credit tinyint
  27. )
  28. create table SC
  29. (sno char(12)references S(sno),
  30. cno char(3)references C(cno),
  31. grade float,
  32. primary key(sno,cno),
  33. )
  34. insert into S values
  35. ('S1','程晓晴','女',21,'CS'),
  36. ('S2','吴玉江','男',20,'CS'),
  37. ('S3','姜云','女',18,'CS'),
  38. ('S4','张峰','男',19,'CS'),
  39. ('S5','张丽丽','女',21,'MA'),
  40. ('S6','李文','女',25,'MA'),
  41. ('S7','李文远','女',19,'MA'),
  42. ('S8','张峰名','男',20,'IS'),
  43. ('S9','王大力','男',21,'IS'),
  44. ('S10','张姗姗','女',22,'IS')
  45. insert into c values
  46. ('C1','C语言程序设计','殷老师',4),
  47. ('C2','计算机网络','王老师',4),
  48. ('C3','数据结构','詹老师',4),
  49. ('C4','数据库系统','詹老师',3),
  50. ('C5','Jave Web','支老师',3)
  51. insert into SC values
  52. ('S1','C1',96),
  53. ('S1','C2',55),
  54. ('S1','C3',84),
  55. ('S1','C5',52),
  56. ('S2','C1',84),
  57. ('S2','C2',90),
  58. ('S2','C4',85),
  59. ('S3','C5',73),
  60. ('S3','C4',Null),
  61. ('S4','C1',50)
  62. use JXGL1
  63. select sno,sname
  64. from S
  65. SELECT SNAME,AGE
  66. FROM S
  67. SELECT * FROM S
  68. select cname
  69. from C
  70. where credit=3
  71. select sname,age
  72. from S
  73. where sno='s1'
  74. select distinct sno
  75. from sc
  76. where grade<60
  77. select sname,age
  78. from S
  79. where age between 18 and 20
  80. select sname
  81. from s
  82. where sex='女'
  83. select sname,sex
  84. from s
  85. where sdept in ('Is','cs')
  86. select sname,sex
  87. from S
  88. where sdept not in('is','cs')
  89. select sname,sno,sex
  90. from s
  91. where sname like '张%'
  92. select sname
  93. from s
  94. where sname like '__'
  95. select sname
  96. from S
  97. where sname not like '张%'
  98. select sname,sno
  99. from S
  100. where sname like '_文%'
  101. select sno,cno
  102. from sc
  103. where grade is null
  104. select sno,cno
  105. from sc
  106. where grade is not null
  107. select sno
  108. from SC
  109. where grade is not null
  110. group by sno

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/40133
推荐阅读
相关标签
  

闽ICP备14008679号