--1.查询全体学生的学号和姓名select sno,sname from student

--2.查询全体学生的详细记录select * from student

--3.查询软件学院的学生姓名,年龄,系别select sname,sage,sdept from studentwhere sdept='CS'

--4.查询所有选修过课程的学生学号(不重复)select distinct sno from sc

--5.查询考试不及格的学生学号(不重复)select distinct sno from scwhere grade<60

--6.查询不是软件学院、计算机系的学生性别、年龄、系别        select ssex,sage,sdeptfrom student where sdept not in('CS','IS')

--7.查询年龄18-20岁的学生学号、姓名、系别、年龄;select sno,sname,sdept,sage from studentwhere sage between 18 and 20/*select sno,sname,sdept,sage from studentwhere sage>=18 and sage<=20;*/

--8.查询姓刘的学生情况select * from studentwhere sname like '刘%'

--9.查询姓刘或姓李的学生情况select * from studentwhere sname like '刘%'or sname like '李%'                   --多字符,单字符通配

--10.查询姓刘且名字为两个字的学生情况select * from studentwhere sname like '刘_'

--11.查询1983年以后出生的学生姓名select sname,sage from studentwhere sage<getdate()-1983

--getdate()获取系统当前时间

--12.创建表 studentgrad(sno,mathgrade,englishigrade,chinesegrade)

计算学生各科总成绩并赋予别名create table studentgrade(sno char(8) primary key,mathgrade tinyint,englishgrade tinyint,chinesegrade tinyint)insert into studentgrade(sno,mathgrade,englishgrade,chinesegrade) values( '95001',85,95,74)insert into studentgrade(sno,mathgrade,englishgrade,chinesegrade) values( '95002',86,91,70)insert into studentgrade(sno,mathgrade,englishgrade,chinesegrade) values( '95003',80,92,71)insert into studentgrade(sno,mathgrade,englishgrade,chinesegrade) values( '95004',81,91,75)insert into studentgrade(sno,mathgrade,englishgrade,chinesegrade) values( '95005',87,97,78)select sno,sum(mathgrade+englishgrade+chinesegrade) as sumgradesfrom studentgrade group by sno

--13.利用内部函数 year()查找软件学院学生的出生年份select sname,(year(getdate())-student.sage )from student where sdept='CS'

--14.利用字符转换函数实现字符联接select sname + '年龄为'+cast(sage as char(2))+'岁'

--字符转换函数cast(),sage后必须要加上as 字符型from student

--15.学生情况,查询结果按所在系升序排列,对同一系中的学生按年龄降序排列select * from student order by sdept ,sage DESC                           --order by   asc升序  desc降序

--16.查询学生总人数select count(*) from student

--17.查询选修了课程的学生人数select  count(distinct sno) from sc

--18.查询选修了1号课程的学生总人数和平均成绩select count(sno),avg(grade)as avggrade from scwhere cno=1/*select count(*),avg(grade)as avggrade from student ,sc where student.sno=sc.sno and sc.cno='1'*/            --two

--19.查询选修2号课程学生的最好成绩select max(grade)as maxgrade from scwhere cno=2

--20.查询每个系的系名及学生人数select sdept,count(*) from student group by sdept/*select sdept,count(sno) from student group by sdept*/                                   --two--

21.查找每门课的选修人数及平均成绩select cno,count(*)as '选修人数',avg(grade)as avggrade from scgroup by cno

--22.查找没有先修课的课程情况select * from course where cpno is null
————————————————
版权声明:本文为CSDN博主「Black博士」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42294230/article/details/80426142

数据库原理实验指导(三)使用SQL语言进行简单查询【转载csdn】的更多相关文章

  1. MySQL从删库到跑路(三)——SQL语言

    作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.SQL语言简介 1.SQL语言简介 SQL是结构化查询语言(Structured Query Language) ...

  2. 数据库系统学习(七)-SQL语言之复杂查询与视图

    第七讲 SQL语言之复杂查询与视图 基本内容 子查询 IN与NOT IN谓词子查询 判断某一表达式的值是否在子查询的结构中 非相关子查询 相关子查询 theta some /theta all谓词子查 ...

  3. 学习笔记:oracle学习三:SQL语言基础之sql语言简介、用户模式

    目录 1.sql语言简介 1.1 sql语言特点 1.2 sql语言分类 1.3 sql语言的编写规则 2.用户模式 2.1 模式与模式对象 2.2 实例模式scott 本系列是作为学习笔记,用于记录 ...

  4. 学习笔记:oracle学习三:SQL语言基础之检索数据:简单查询、筛选查询

    目录 1. 检索数据 1.1 简单查询 1.1.1 检索所有列 1.1.2 检索指定的列 1.1.3 查询日期列 1.1.4 带有表达式的select语句 1.1.5 为列指定别名 1.1.6 显示不 ...

  5. LINQ to Sql系列二 简单查询和联接查询

    这一篇文章主要总结LINQ to sql的简单查询(单表查询)和联接查询(多表查询) 单表查询 需求是我们要输出TClass表中的结果.使用了from-in-select语句,代码如下: public ...

  6. SQL语言 之 数据查询

    在Oracle 数据库中,SELECT 语句的基本语法为: SELECT [ALL|DISTINCT] column_name [,expression...] FROM table1_name [, ...

  7. SQL语句之-简单查询

       SQL 语句的语法顺序是: SELECT[DISTINCT] FROM WHERE GROUP BY HAVING UNION ORDER BY 一.查询SELECT 1.查询全部列:SELEC ...

  8. asp.net 可视化操作(二)——Sql数据库连接及简单查询功能的实现

    目录 连接数据库 利用repeater控件实现数据显示 查询功能 页面CSS美化 数据插入.更新-- 连接数据库 添加test.aspx 添加控件SqlDataSource,选择配置数据源 选择新建连 ...

  9. 哈工大数据库系统 实验:练习并熟练掌握交互式 SQL 语言

    实验目的:基于给定的 OrderDB 数据库, 练习并熟练掌握交互式 SQL 语言实验环境:sql sever 2008 附:OrderDB 表结构及表间的关系 /* 1 查询职工工资按高低排序的前2 ...

随机推荐

  1. 【Hexo】使用Hexo+github pages+travis ci 实现自动化部署

    目录 一.说明 二.成品展示 三.前期准备 本地安装 node.js 本地安装 git github 账号 创建仓库 travis ci 账号 四.安装 Hexo 五.使用 hexo 搭建博客 六.部 ...

  2. 使用django开发论坛输出调试信息时附加远程客户端IP地址!

    前言 最近使用django开发了个匿名社区(哈士奇社区 4nmb.com),但是有个问题一直困扰我半天,就是如何在django调试信息上输出远程客户端的真实IP地址,在网上找了很多资料也没见人遇到过, ...

  3. RocketMQ搭建全过程

    RocketMQ下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.3.0/rocketmq-all-4.3.0-bin-relea ...

  4. file download hash mismatch

    在linux中使用cmake时,遇到了"file download hash mismatch",同时status显示"unsupported protocol" ...

  5. Linova and Kingdom(树型-贪心)

    题目大意:给定一棵树,1为首都(首都可以是工业城市也可以是旅游城市),一共有n个点. 其中要选出k个工业城市,每个工业城市出一个代表去首都,其快乐值是其途径旅游城市(非工业)的个数 求所有快乐值相加的 ...

  6. Spring Boot在Controllder中常用注解

    1.@RestController @RestController 相当于@Controller+@ResponseBody 注解如果使用@RestController 注解Controller 中的 ...

  7. 安卓集成Unity开发示例(一)

    本项目目的是在移动端的 Native App 中以库的形式集成已经写好的 Unity 工程,利用 Unity 游戏引擎便捷的开发手段进行跨平台开发. Unity官方文档 Unity as a Libr ...

  8. STM32 TIM 编码器模式采集编码器信号

    layout: post tags: [STM32] comments: true 文章目录 @[toc] 什么是正交解码? 编码器接口模式 标准库接口 TIM_TimeBaseInitTypeDef ...

  9. Git使用教程之SSH连接方式配置(二)

    什么是GitHub?这个网站就是提供Git仓库托管服务的. 什么是SSH Key?你的本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,大白话理解就是这两个仓库如果要进行远程同步,则我们需 ...

  10. springMVC的自定义annotation(@Retention@Target)详解

    自定义注解: 使用@interface自定义注解时,自动继承了java.lang.annotation.Annotation接口,由编译程序自动完成其他细节.在定义注解时,不能继承其他的注解或接口.@ ...