美文网首页
第二天上午、修改和查询数据

第二天上午、修改和查询数据

作者: 别学编程 | 来源:发表于2020-08-06 08:54 被阅读0次

修改数据:

首先插入数据

···

insert into stu values(8,'张三',sysdate,'男','412820199910102440',2);

insert into stu values(6,'老八',sysdate,'男','412820199910102770',2);

insert into stu values(7,'李四',sysdate,'男','412820199910102550',2);

···

修改数据代码

```

--修改数据

select * from stu; --首先查询下数据

update stu set clazzNo = 1,sex='女' --改所有人为女,这个不要执行,不然后果自负

update stu set clazzNo = 5,sex='女' where stuName = '李四' --更改条件是姓名为李四的改变班号性别,what??性别也能改

```

查询数据:

把昨天下载的sql文件打开执行一下就有需要查询的数据了。

需要查新的数据都在这个里面

每个数据表的作用说明

查询指定三列数据

不想看英语怎么办,指定列重命名帮你解决

又有重复列,不想看这些怎么办,试试下面的语句吧,distinct太强大

计算年工资

数字类型能计算,字符类型的呢,可以拼接,下面代码

条件查询

···

--查询数据:条件查询(> >= < <= != =)

select * from emp where deptno=10;

select * from emp where sal >= 3000;

--逻辑运算符 and or not

select * from emp where deptno = 10 and sal > 2000 and ename = 'KING';

select * from emp where deptno = 20 or sal > 2000;

select * from emp where (deptno = 20 or deptno = 30) and sal > 2000;

select * from emp where not (sal >= 3000)

--判断空is null, is not null

select * from emp where comm is not null

--between and

select * from emp where sal between 1000 and 2000;

select * from emp where sal >= 1000 and sal <= 2000;--可换做between来做查询

--in 在某个数据里面取值

select * from emp where deptno = 20 or deptno = 30;--可换做in来做查询

select * from emp where deptno in (20,30);

--模糊查询like(%表示0或多个任意字符,_表示任意一个字符)

select * from emp where ename = 'SMITH';--仍然是精确查询

select * from emp where ename like '%S%';

select * from emp where ename like 'F___';

--tel is 135, 倒数第二个为4

select * from paper where tel like '135______4_'

···

代码图片以及执行结果

作业题:

---查询数据:简单查询

--查询所有列

select * from emp;--员工表

select * from dept;--部门表

select * from salgrade;--工资等级表

--查询指定列

select empno,ename,sal from emp;

--查询指定列:重命名

select empno 员工编号,ename 姓名,sal,deptno id from emp;

--去除重复

select distinct deptno from emp;

--计算列(+-*/注意需要在数字类型的列)

select empno,ename,sal*12 年薪 from emp;

--列拼接||(姓名 is a job)

select ename||' is a '||job from emp;

---查询数据:条件查询

--比较运算符 > >= < <= != =

select * from emp where deptno!=10;

select * from emp where sal >= 3000;

--逻辑运算符 and与  or或  not非

select * from emp where deptno = 10 and sal > 2000 and ename = 'KING';

select * from emp where deptno = 20 or sal >2000;

select * from emp where (deptno = 20 or deptno = 30) and sal >2000;

select * from emp where not sal >=3000;

--is null,is not null

select * from emp where comm is null;

select * from emp where comm is not null;

--between and(>=  and <=)

select * from emp where sal between 1000 and 3000;

select * from emp where sal >= 1000 and sal <= 2000;

--in

select * from emp where deptno in (20,30);

select * from emp where deptno = 20 or deptno = 30;

--模糊查询like,%(0-多个任意字符),_(一个任意字符)

select * from emp where ename like '%S%';--名字中含有S

select * from emp where ename like 'F___';

select * from xxx where tel like '135______4_' and sex='';--tel  135开头,倒数第二个为4

--练习作业题

---练习

1、检索dept表中的所有列信息

2、检索emp表中的员工姓名(ename)、月收入及部门编号

3、检索emp表中员工姓名、雇佣时间1(默认显示方式)、及雇佣时间2(yyyy-mm-dd显示方式)

4、检索emp表中的部门编号及工种,并去掉重复行,并根据部门号排序。

5、检索emp表中的员工全名及全年的月收入

6、检索emp表,用is a 这个字符串来连接员工姓名和工种两个字段,如:King is a AD_PRES   

7、检索月收入大于2000的员工姓名及月收入。

8、检索月收入在1000元到5000元的员工姓名、月收入及雇佣时间。

9、检索以S开头的员工姓名及月收入。

10、检索员工姓名中的第二个字符是A的员工姓名及月收入。

11、检索emp表中月收入是2000的或是5000的员工姓名及部门编号

12、显示在部门10中岗位SALESMAN的所有雇员信息

13、显示工资高于3000或岗位为CLERK的所有雇员信息

14、检索emp表中有提成的员工姓名、月收入及提成。

15、检索emp表中部门编号是30的员工姓名、月收入及提成,并要求其结果按月收入升序、然后按提成降序显示。

select * from emp order by sal;--排序order by 列名 asc/desc(desc降序,asc升序,默认为升序)

select * from emp order by sal,comm desc;

相关文章

  • 第二天上午、修改和查询数据

    修改数据: 首先插入数据 ··· insert into stu values(8,'张三',sysdate,'男...

  • arango增删改查

    arango实践 插入数据 修改数据 插入数据 查询数据 复杂查询 多表查询

  • arango的AQL

    arango实践 插入数据模板 修改数据模板 插入数据 查询数据 复杂查询 多表查询 图查询

  • 数据库之增删改查

    增加数据(插入) 修改数据 删除数据 查找数据 基础数据 高级查询 多表查询 准备三个表 多表查询 将学生表和班级...

  • 06.DQL查询语句--列控制

    DQL(Data Query Language) 数据查询语言,用来查询记录(数据) 查询语句不会修改数据库 准备...

  • SQL之DQL

    DQL用于从数据库查询数据,并不会修改数据 基本查询 条件控制 查询排序 分组查询 limit限制 一.基本查询 ...

  • sqlite数据库

    创建数据库 修改数据库 插入操作 修改 查询操作

  • 模型操作(CURD)

    语法:类名.query.xxx 获取查询集: 数据操作:在事务中处理,数据插入 修改和删除基于查询 模型展示 向学...

  • MongoDB-第四章-查询

    查询 对MongoDB进行新增、修改和删除后,最主要的功能就是对数据(集合)进行查询,MongoDB支持丰富的查询...

  • JAVA Web学习(15)___第10章 Java Web的数

    10.3.2 查询数据 10.3.3 修改数据 10.3.4 删除数据 ShowBook.jsp此页面包含查询、修...

网友评论

      本文标题:第二天上午、修改和查询数据

      本文链接:https://www.haomeiwen.com/subject/mamirktx.html