简单使用数据库数据库

查询
	--注释 
	--查询公式: select *|字段名字1 别名,字段名字2 (as) 别名... from 表名;
	--执行顺序:--from--select确定结果集
	--查询dept表中的所有信息
	SELECT * FROM DEPT;
	--查询雇员表中所有员工的员工编号,员工姓名,上级编号
	--要查询的数据: empno,ename,mgr
	--数据的来源:emp
	--条件:
	select empno,ename,mgr from emp;
	--所有员工的部门标号
	select deptno from dept;
	select deptno from emp;
	--去重 distinct
	select distinct deptno from emp;
	--完全相同的数据才能去重
	select distinct deptno,ename from emp;
	--表达式
	select distinct 1+1 from dept;
	--计算器
	select empno,ename,123*456 from emp;
	--别名  字段 (as) 别名  表名 别名
	select empno as 员工编号,ename "员工 姓名",1+1 "getSum" from emp  e;
	--原样输出  ""  小写别名,中文中带有空格...非标准写法
	--''字符串
	select 'haha' "haha" from emp;
	--字符串拼接   ||
	select 'SXT'||ename from emp;
	--伪列:表中不存在的列  :字符串,表达式...
	--虚表:没有任何数据  dual
	select distinct 456*789,sysdate from emp;
	select sysdate from dual;
	--null 空值
	--查询员工姓名,员工的薪资,员工的奖金
	select ename ,sal , comm from emp;
	--null和数字运算,结果还是null
	--null和字符串运算,结果是原串,null相当于空串
	--给公司的每个员工+100鼓励金
	select ename ,sal , comm "原奖金",comm||'100' "新奖金" from emp;
	--处理null值  nvl(参数1,参数2)  如果参数1为null,函数的返回值结果为参数2,如果参数1不为null,函数的返回值结果为参数1
	select ename ,sal , comm "原奖金",nvl(comm,0)+100 "新奖金" from emp;
条件查询
	-- 查询员工名字为'SMITH'的员工信息
	select * from emp where ename='SMITH';
	--比较条件  = 、>、 <、 >=、 <=、 !=、 <>
	--除了'SMITH'的所有员工的员工姓名和员工编号
	select empno,ename from emp where ename!='SMITH';
	select empno,ename from emp where ename<>'SMITH';
	select empno,ename from emp where not ename='SMITH';
	--查询呢薪资大于800的员工信息
	select * from emp where sal>800;
	--and且、 or或、 not非
	--查询工种为CLERK的,并且是30部门的员工信息
	select * from emp where job='CLERK' and deptno=30;
	--查询工种为CLERK的,或者是30部门的员工信息
	select * from emp where job='CLERK' or deptno=30;
	--查询不是工种为CLERK的,也不是30部门的员工信息
	select * from emp where job!='CLERK' and deptno!=30;
	select * from emp where not job='CLERK' and not deptno=30;
	select * from emp where not (job='CLERK' or  deptno=30);
	--查询有奖金的人
	select * from emp where comm is null;
	--查询没有奖金的人
	select * from emp where not comm is null;
	select * from emp where comm is not null;
	--条件查询: select *|字段名字.. from 表名 where 行过滤条件;
	--执行顺序: from--where--select
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值