前言
sql语言在大数据开发是比较重要的一部分,对sql语言进行总结能更好地熟悉自己的大数据开发业务。j
一、部分函数
concat(,,_),顺序链接每一个字符
concat_ws(’ ',last_name,first_name)使用第一个字符连接后两个每一个字符
unique_idx_firstname:为first_name创建唯一索引
创建视图:actor_name_view
创建索引:idx_emp_no
构造一个触发器audit_log,在向employee_test表中插入一条数据时,触发相关的数据到audit种
更新操作:update
limit(index,index):以第一个索引为初始值,取第二个索引的个数。
二、嵌套查询(子查询)
定义:⼀个内层查询语句(select-from-where)块可以嵌套在另外⼀个外层查询块的where⼦句中,其中外层查询也称为⽗查询,主查询。
内层查询也称⼦查询,从查询。⼦查询⼀般不使⽤order by⼦句,只能对最终查询结果进⾏排序。
另⼀种定义:在⼀个SELECT 语句的WHERE ⼦句或HAVING ⼦句中嵌套另⼀个SELECT 语句的查询称为嵌套查询,⼜称⼦查询。
嵌套查询的⼯作⽅式是:先处理内查询,由内向外处理,外层查询利⽤内层查询的结果嵌套查询不仅仅可以⽤于⽗查询select语句使⽤。还可以⽤于insert、update、delete语句或其他⼦查询中。
I.简单的子查询
select name,age
from person
where age > ( select age
from person
where name = '张三');
II.like嵌套查询
select count(distinct(Tname)) --查询姓“张”的⽼师的个数
from Teacher
where Tname like '张%';
III.in嵌套查询
in关键字⽤于where⼦句中⽤来判断查询的表达式是否在多个值的列表中。返回满⾜in列表中的满⾜条件的记录。
select name
from person
where countryid in ( select countryid
from country
where countryname = '中国
IV.some嵌套查询
select name from person
where countryid = some ( select countryid from country --⽤等号和以下查询到的值⽐较,如果与其中⼀个相等,就返回
where countryname = '中国');
V.all嵌套查询
select name from person
where countryid > all ( select countryid from country --当countryid⼤于以下返回的所有id,此结果才为True,此结果才返回
where countryname = '中国');
VI.exists嵌套查询
SELECT * FROM Person
WHERE exists ( SELECT 1);
VII.返回新数据表的⼦查询
Select a.Sno from (select Sno,score from SC where Sno='001') a,
(select Sno,scorefrom SC where Cno='002') b
Where a.score>b.score and a.Sno=b.Sno;
总结
综合面试情况以及练习来看,sql语言比较重要的还是对实际情况进行总结