黑马程序员c语言教程:sql语言课堂强化_黑马程序员c语言教程

2020-02-28 其他范文 下载本文

黑马程序员c语言教程:sql语言课堂强化由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“黑马程序员c语言教程”。

sql语言课堂强化 select a, b, c select.....(多个列)from.....一个表(多个表)where....(条件)group by...(分组)--难点 having......(分组过滤)order by 1(排序)

SQL语言是数据库的“键盘”,请大家重视基本功的训练

课堂考试 9:10 左右 学员到我笔记本上 上机操作 求所有部门的平均奖金

select avg(nvl(comm, 0))from emp;

select avg(sal)from emp;求各部门的平均薪水

select deptno, avg(sal)from emp group by deptno

====>错误案例

select deptno, ename, avg(sal)from emp group by deptno /

select d from emp group by a, b, c 求各部门每个工种的平均薪水, 并显示部门编号、工种、平均薪水

select deptno, job, avg(sal)

from emp group by deptno, job--先按deptno、job分组,出来n组数据,在这个基础之上,再进行计算求各部门每个工种大于2000的薪水 select sal from emp where sal>2000

4-1 求各部门每个工种,平均薪水大于2000的薪水

select deptno, job, avg(sal)from emp group by deptno, job having avg(sal)>2000 求10号部门的平均工资(2种写法)select deptno, avg(sal)from emp where deptno=10 group by deptno

select deptno, avg(sal)from emp group by deptno having deptno = 10创建一个学生表

sid sname

email sex age 7 并向表中插入一条数据

create table student(sid number, sname varchar2(20), email varchar2(64), sex number,age number)insert into student(sid, sname, email, sex, age)values(1, 'tom11', '11@163.com', 1, 20)

//只显示大于4个人的部门信息

select deptno, count(*)from emp group by deptno having count(deptno)> 4 /

--创建表

--1 查询 员工号 姓名 月薪 年薪 年收入 部门名称

select e.deptno, e.ename, e.sal, e.sal*12 yearsal,(e.sal*12+nvl(e.comm,0))incoming , d.dname from emp e, dept d where e.deptno = d.deptno

====>

---2 创建一个表, 把第一步骤查询的信息,存放在另外一张表中 create table s1 as(select e.deptno, e.ename, e.sal, e.sal*12 yearsal,(e.sal*12+nvl(e.comm,0))incoming , d.dname from emp e, dept d where e.deptno = d.deptno)

create view myview1 as(select e.deptno, e.ename, e.sal, e.sal*12 yearsal,(e.sal*12+nvl(e.comm,0))incoming , d.dname from emp e, dept d where e.deptno = d.deptno)

create table empincome as

select e.empno, e.ename, e.sal, e.sal*12 annalsal, sal*12+nvl(comm, 0)income, d.dname from emp e, dept d where e.deptno = d.deptno;

--创建表的同时copy数据

《黑马程序员c语言教程:sql语言课堂强化.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
黑马程序员c语言教程:sql语言课堂强化
点击下载文档
相关专题 黑马程序员c语言教程 语言 黑马 程序员 黑马程序员c语言教程 语言 黑马 程序员
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文