hivesql和mysql常见问题
1) EXISTS ()括号里只要有返回值就会执行 EXISTS 之前的语句
2) select 1 的问题
3) in查询相当于多个or条件的叠加,这个比较好理解,比如下面的查询
select * from user where userId in (1, 2, 3);
等效于
select * from user where userId = 1 or userId = 2 or userId = 3;
not in与in相反,如下
select * from user where userId not in (1, 2, 3);
等效于
select * from user where userId != 1 and userId != 2 and userId != 3;
总的来说,in查询就是先将子查询条件的记录全都查出来,假设结果集为B,共有m条记录,然后在将子查询条件的结果集分解成m个,再进行m次查询
值得一提的是,in查询的子条件返回结果必须只有一个字段,例如
select * from user where userId in (select id from B);
而不能是
select * from user where userId in (select id, age from B);
而exists就没有这个限制
4) group by 加上limit 不能实现topN的需求
再用limit的时候所有的group by 都是一个组,只会取出全部的前几条limit数据
5)要想实现order by 必须只能有一个reduceTask
只需要有reduce阶段,并且reduceTask为1