SQL基础讲义
简单查询
1、查询全部学生的信息
select * from xs
2、查询学生的姓名和年龄
select xm, year(date())-year(csrq) as age from xs
3、查询学生的平均年龄
select avg(year(date())-year(csrq) ) as 平均年龄 from xs
4、查询学生的人数
select count(*) from xs
5、查询选修了课程的学生学号
select distinct xh from cj
6、查询选修了课程的学生人数
select count(distinct xh) from cj
7、查询有多少个不同的姓氏
select distinct left(xm,2) as 姓氏 from xs
8、查询所有成绩的平均分
select avg(cj) as 平均分 from cj
9、查询02课程的平均分
select avg(cj) from cj where kcbh='02'
10、查询成绩不及格的学号
select distinct xh from cj where cj<60
11、查询成绩不及格的人数
select count(distinct xh) from cj where cj<60
12、查询出生日期在1993.1.1之前的同学
select * from xs where csrq<{^1993.1.1}
13、查询成绩在70-80之间的学号、课程号和成绩
select xh, kcbh, cj from cj where cj between 70 and 80
14、查询所有姓"李"的同学
select * from xs where xm like "郝%"
15、查询姓名中包含"毛"字的同学
select * from xs where xm like "%毛%"
16、查询姓名中第二个字是"思"的同学
select * from xs where xm like "_思%"
17、查询成绩为60、70、80和90分的学号、课程号和成绩
select xh, kcbh, cj from cj where cj in (60,70,80,90)
18、查询籍贯不是湖南或四川的同学
select * from xs where jg not in ("湖南","四川")
19、查询成绩为空的学号和课程号
select xh, kcbh from cj where cj is null
嵌套查询
1、查询选修了"软件工程"的同学的学号
select xh from cj where xh in (select xh from kc where kcmc='软件工程')
2、查询课程表中没有被任何学生选修的课程号和课程名
select kcbh, kcmc from kc where kcbh not in (select distinct kcbh from cj)
3、查询没有选修任何课程的学生学号和姓名
select xh, xm from xs where xh not in (select distinct xh from cj)
4、查询成绩为最高分的学号和成绩
select xh, cj from cj where cj = (select max(cj) from cj )
5、查询成绩大于平均分的学号和成绩
select xh, cj from cj where cj > (select avg(cj) from cj)
6、查询成绩大于02课程平均分的学号和成绩
select xh, cj from cj where cj > (select avg(cj) from cj where kcbh='02')
7、查询02课程中成绩大于平均分的学号和成绩
select xh, cj from cj where kcbh='02' and cj > (select avg(cj) from cj)
8、查询02课程中成绩大于02课程平均分的学号和成绩
select xh, cj from cj where kcbh='02' and cj > (select avg(cj) from cj where kcbh='02')
9、查询02课程中成绩大于04课程平均分的学号和成绩
select xh, cj from cj where kcbh='02' and cj > (select avg(cj) from cj where kcbh='04')
10、查询成绩小于所选修课程平均分的学号和成绩(相关子查询,了解即可)
select xh, cj from cj a where
-简单查询1_计算机软件及应用_IT/计算机_专业资料。...SQL Server的数据库查询使用T-SQL语句, 其基本的...12】在Book表中,查询“Price”在40和50之间的图书...
SQL 单表查询_电脑基础知识_IT/计算机_专业资料。实验三一、实验目的 单表查询 掌握简单SQL 查询语句的应用,包括like、top、order by、compute 、聚集函数的应 ...
实验三 SQL简单查询_计算机软件及应用_IT/计算机_专业资料。实验三 SQL 简单查询实验步骤: 1. 创建学生表 student、课程表 course 和选课表 SC,并输入数据。 ...
简单查询 CJ表(学生数据库中表) SQL查询 ? 简单查询例14:查询XJ表中全体学生...联接查询直接使用 SELECT…FROM…WHERE基本查询块来实现,在FROM 后面给出多表,用...
基本sql查询_IT/计算机_专业资料。基本sql查询2 基本 sql 查询 目标掌握简单查询(单表) 掌握联接查询(多表) 内联接 交叉联接 外联接 掌握分组聚合语法 理解并...
四、实验步骤 1 基本操作实验 (1)简单查询实验 l)用 Transact-SQL 语句表示下列操作.在学生选课库中实现其数据查询操作. ①求数学系学生的学号和姓名。 ②求...
SQL 基本表查询_计算机软件及应用_IT/计算机_专业资料。数据库中SQL基本表查询...注意:*的作用 2.查询 STUDENT 表中计算机系学生的全部信息、查询 STUDENT 表中...
4页 免费 做LOGO的三十种技巧 15页 5财富值 SQL简单查询及函数 24页 免费...数据查询-基础查询全部的行和列 SELECT * FROM Students 查询部分行 SELECT S...
创建简单查询获得“管理员”信息_IT/计算机_专业资料。本篇文档是职业高中...(在学生回答复习问题的基础上进一步提 出问题)那么什么是 SQL 语言?如何通过 ...
SQL sever 基本查询语句_IT/计算机_专业资料。SQL必须知道的 查询语句实验5 一、 实验目的 1. 2. 3. 4. 5. 6. 7. 8. SQL Server 2000 简单查询 掌握...
热门文档