SQL知识点

--聚合函数:intersect union exceot
--聚集函数:max min sum count avg
--集合 交集 intersect intersect all

create table emp(empno int);
insert into emp values(7369);
insert into emp values(7499);
insert into emp values(7859);--聚合函数:intersect  union exceot
--聚集函数:max min sum count avg
--集合  交集  intersect   intersect all
insert into emp values(7369);
select * from emp;

---------------------------------集合----------------------------------------------

--聚合函数:intersect  union exceot
--聚集函数:max min sum count avg
--集合  交集  intersect   intersect all
select * from emp a where a.empno in(7369,07499) intersect select * from emp b where b.empno in (7369);  --  从交集结果中去掉重复的

select * from emp a where a.empno in(7369,7499) intersect all select * from emp b where b.empno in (7369); --从交集结果中不去掉重复的

--集合  并集  union  union all
select * from emp a where a.empno in(7369,7499) union select * from emp b where b.empno in (7369); --从并集结果中去掉重复的

select * from emp a where a.empno in(7369,7499) union all select * from emp b where b.empno in (7369); --从并集结果中不去掉重复的


--集合 差集  except    except all
select * from emp a where a.empno in(7369,7499) except select * from emp b where b.empno in (7369); --从差集结果中去掉重复的

select * from emp a where a.empno in(7369,7499) except all select * from emp b where b.empno in (7369); --从差集结果中不去掉重复的

--连接 横向扩展
--组合(集合)纵向扩展


---------------子查询:(用的比较少) 相关子查询  非相关子查询-------------------

/*非相关子查询   先进行子查询 在进行外部查询
相关子查询  外部查询执行一次  子查询就执行一次
*/

--in  exists  按照最优化匹配原则 拿最小记录匹配大记录   
/*
用in 会优先子查询然后匹配外层查询   
用exists 会优先外层查询然后匹配子查询 
*/

/*
函数
*/

select current_date + interval '1 month'; --当前日期加一个月

select current_date + interval '1 week'; --当前日期加一周

select current_date + interval '1 day'; --当前日期加一天
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
select current_time + time '01:00';     --当前日期加一小时

select current_time + time '00:01';     --当前日期加一分钟

select current_time + time '00:00:01';  --当前日期加一秒

select now();

select current_database()   /*当前数据库的名字*/
select current_schema()   /*当前模式的名字*/
select current_user     /*当前执行环境下的用户名*/
select Version()

数据类型转换
select to_char(125,'999')
select to_char(125,'99999D99')
select to_char(125.8::real,'999D9')
select to_char(-125.8,'S999D99')
select to_char(current_timestamp,'HH12:MI:SS')
select to_char(interval '15h 2m 12s','HH24:MI:SS')
select to_date('05 Dec 2000','DD Mon YYYY')
select to_number('12,454.8-','99G999D9S')
select to_timestamp('05 Dec 2000','DD Mon YYYY')

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,555评论 0 13
  • 目录 什么是SQLSQL基本语法排序-ORDER BY选取不重复的数据-DISTINCTWHERE子句LIKE 操...
    何兮_HC阅读 2,682评论 0 2
  • 开发DBA:数据库设计(E-R关系图)、SQL开发、内置函数、存储例程(存储过程和存储函数)、触发器、事件调度器(...
    drfung阅读 649评论 0 0
  • 介绍几个MySQL存储引擎 答:MySQL将数据用各种不同的技术存储在文件中,这些技术中的每一种技术都使用不同的存...
    Y了个J阅读 230评论 0 0
  • 1.GROUP BY 语句 GROUP BY语句用于结合合计函数,根据一个或多个列对结果集进行分组。 SQL GR...
    廖马儿阅读 652评论 0 0