5.8杂记
1where是groupby 之前,having是groupby之后
-- 2.where不能出现多行函数,having中可以出现多行函数
select各个子句的执行顺序
-- from where group by select having order by
select deptno,avg(sal) from emp -- 字段不能和分组函数共存,除非该字段是分组group by字段
SELECT * FROM EMP WHERE JOB NOT IN ('CLERK','MANAGER')-- 不包括
select * from emp where comm is null --为空
select * from emp where comm is not null -- 不为空
select * from emp where hiredate > '02-4月-1981' --默认格式
-函数的分类
--单行函数 对(多行)每一条记录进行操作,分别产生一条记录 14---14 lower(ename),upper(ename),initcap(ename)
--多行函数 对(多行)每一条记录进行操作,结果只产生一条记录 max(sal),min(sal),sum(sal),avg(sal)
自动转换
select 12+'23' from dual; -- 35 + 只是算术运算符 自动转换成数字
select 12+'23abc' from dual; --错误
select 12||'23abc' from dual; -- || 不是or运算,而是字符串拼接运算符
select * from emp where hiredate < '17-12月-1985' --自动转换
日期---字符串
--方法1:自动转换
select * from emp where hiredate < '17-12月-1985'
--方法2:手动转换:hiredate变成字符串to_char()
select * from emp where to_char(hiredate,'YYYY/MM/DD') >'1985/12/17'
--方法3:手动转换:'17-12月-1985'变成日期 to_date()
select * from emp where hiredate > TO_DATE('1985/12/17','YYYY/MM/DD')
select empno,hiredate,to_char(hiredate),to_char(hiredate,'YYYY/MM/DD')
,to_char(hiredate,'YYYY-MM-DD') ,to_char(hiredate,'YYYY"年"MM"月"DD"日"')from emp
多行函数,操作多行数据,结果只有一行
select count(distinct job) from emp; 去重统计个数
insert
insert into emp (empno,ename,sal,deptno)values (9988,'1234',900,40) --只给部分列赋值