大数据学习——hive的sql练习题
2023-09-11 14:18:37 时间
ABC三个hive表 每个表中都只有一列int类型且列名相同,求三个表中互不重复的数
create table a(age int)
row format delimited
fields terminated by ',';
create table b(age int)
row format delimited
fields terminated by ',';
create table c(age int)
row format delimited
fields terminated by ',';
a.txt
1
2
3
4
5
6
7
8
9
b.txt
2
3
11
12
14
15
16
18
35
6
7
8
c.txt
1
2
3
11
5
6
7
8
20
30
40
sql:
select * from (select a.* from a full outer join b on a.age=b.age full outer join c on a.age =c.age where (a.age is not null and b.age is null and c.age is null) or (b.age is not null and a.age is null and c.age is null) or (c.age is not null and a.age is null and b.age is null) union select b.* from b full outer join a on a.age=b.age full outer join c on b.age =c.age where (a.age is not null and b.age is null and c.age is null) or (b.age is not null and a.age is null and c.age is null) or (c.age is not null and a.age is null and b.age is null) union select c.* from c full outer join b on c.age=b.age full outer join a on a.age =c.age where (a.age is not null and b.age is null and c.age is null) or (b.age is not null and a.age is null and c.age is null) or (c.age is not null and a.age is null and b.age is null)) d where d.age is not null ;
运行结果:
sql:
select age,count(age) as c1 from (select age from a union all select age from b union all select age from c) t_union group by age having c1=1;
相关文章
- SQL存在一个表而不在另一个表中的数据
- 【SQL 学习】case 表达式
- 【SQL 学习】层次化查询之CONNECT BY 和 START WITH
- 【SQL 学习】表连接--natural join 的一个bug
- sql server中创建数据库和表的语法
- sql基本操作语句
- SQL Tune Report–sqltrpt.sql
- 读书笔记--SQL必知必会10--分组数据
- sql 语句系列(闰年)[八百章之第十九章]
- 掀开SQL的神秘面纱,将优化进行到底
- 【学习总结】SQL的学习-5-性能调优常用方法介绍与数据导入导出
- 【学习总结】SQL的学习-4-常用函数介绍
- 【学习总结】SQL的学习-3-数据查询
- 【学习总结】SQL的学习-1-初识数据库与sql
- 【学习总结】SQL学习总结-总
- sql 语句系列(记录时间差)[八百章之第十八章]
- SQL语句中单双引号的理解
- Sql Server连接数据库(Windows模式及不用密码及用户名模式)
- Sql Server 查询表中各列名称、表中列数
- One order search dynamic SQL build logic
- sql 语句的limit的用法
- 全国 省市 自治区的数据库sql生成
- 怎么查 ODBC Driver for SQL Server
- Go组件学习——database/sql数据库连接池你用对了吗
- 利用墨者靶场学习SQL注入——sqlmap果然是利器啊