1. 程式人生 > >HiveSql(3)HiveSQL與oracle SQL的區別

HiveSql(3)HiveSQL與oracle SQL的區別

HiveSQL與oracle SQL的區別

1、hive sql暫時不能使用in,不支援where字句中的子查詢。可以利用leftsemi join來實現in。

Hive:

Select * from employee e left semi joindept d on (e.deptno=d.deptno)

小表放在join左邊。

Left semi join是in/exist在hive中的一種更為高效的實現。

Oracle:

Select * from employee e where e.deptno in (selectd.deptno from dept d))

2、hive sql同樣不支援not in。可以利用leftouter join來實現。

Hive:

Select e.* from employee e left outer joindept d on(e.deptno=d.deptno) where d.deptno is null

Oracle:

Select * from employee e where e.deptno notin (select d.deptno from dept d))

3、join上的不同

Hive:

Select * from employee e join dept d on (e.id=d.id)

Oracle:

Select * from employee e,dept d where e.id=d.id

4、rank函式的不同

Hive:

Select e.name,e.dept,e.salary,rank(e.dept,e.salary)

From (Select name,dept,salary from employeedistributed by dept sort by dept,salary desc)e

Oracle:

Select name,dept,salary,rank() over(partitionby dept order by salary desc) from employee

5、min函式的不同

Hive:

Select dept,tmp.m

From (Select dept,min(salary) m fromemployee group by dept) tmp

On employee.dept=tmp.dept

Oracle:

Select dept,min(salary) over (partition bydept) from employee