group by---按照某几列分组

having---分组之后的过滤

like(%, _)---模糊查询, %表示   select * from emp e where e.empname like '%ccc%'

distinct---去除重复    select distinct e.empname from emp e;

between...and(闭合区间, 即包括前面的数, 也包括后面的数)   select * from emp e where e.id between 5 and 10;

all---表示一个集合中所有的元素      select * from emp e where e.intime>= all(select intime from emp);

any/some---表示一个集合中任意一个元素

 

常用函数

to_char---转换成字符型数据

vselect to_char (sysdate,'yyyy-mm-dd hh:mi:ss') from dual; 时间是12小时制

select to_char (sysdate,'yyyy-mm-dd pmhh:mi:ss') from dual; 时间前面带上午下午

select to_char (sysdate,'yyyy-mm-dd pmhh:mi:ss') from dual; 12小时制时间前面不带0(1:25:25)

select to_char (sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; 24小时制时间

select to_char (sysdate,'yyyy-mm-dd pmhh24:mi:ss') from dual; 24小时制前面显示上午下午(没用)

 

to_date---转换成日期型数据        dual(数据库内的一些虚拟抽象表)

      select to_date('2017-04-25 13:56:30','yyyy-mm-dd hh24:mi:ss')from dual;

 

分组函数:

mod---取余函数

avg---平均数函数    select avg(e.sal) from emp e;

sum---求和函数(☆任何数字与NULL相加,结果都为NULL!!!)  select sum(e.sal) from emp e;

count---计数函数 (空的不计数,只记有的)   select count(e.comm) from emp e

decode---类似于分支语句的函数    select decode(e.ssex, 0,'女',1,'男','不详') 性别 from emp e;

substr---分割字符串    select substr('qweasdfqweqwr',2,4) from dual;(从第二个w开始取,取出四个)

max---取最大值函数    select e.deptid, max(e.intime) 每组最大 from emp e group by e.deptid;

select * from emp e where e.intime = (select max(intime)from emp);  (查表里日期最大的)

min---取最小值函数    select min(e.intime) from emp e;

trunc---取整函数(小数点位数全部舍去,没有四舍五入)  select trunc(12.3) from dual;

ceil---向上取整函数  (取上一位整数,没有四舍五入)  select ceil(12.3) from dual;

floor---向下取整   (取下一位整数,没有四舍五入) select floor(12.8) from dual;

nvl---过滤空值函数  select nvl(e.comm,'') from emp e;(两个参数前面是有就显示原有的,后面是没有参数要显示的内容)

nvl2---过滤空值函数2   select nvl2(e.comm,'有','没有')  是否空from emp e;(三个参数:查询源,有参数要显示的内容,无参数要显示的内容)

lower---将字母全部改为小写   select lower ('aBcD') from dual;

upper---改为大写            select upper ('aBcD') from dual;

concat---连接两个字符串(只能连接2字符串多了报错)  select concat('hello','world') from dual;

order by 1,2  

 --select p.id,p.pcode,p.pname from product p order by 1 desc,2,3(数字顺序代表select 后面查询内容优先按谁的顺序排列,列表还是按照p.id,p.pcode,p.pname排序)

group by 增强版

语法: select p.toma, p.ptype, sum(p.lastcou) from product p group by rollup(p.toma, p.ptype)

posted on 2017-06-25 20:05  汐风雪夜  阅读(3539)  评论(0编辑  收藏  举报