随笔分类 - SQL
摘要:1、创建测试表:drop table if exists tab_null_operator;create table tab_null_operator as select 1 as id,'chavin' as name union all select 2 as id,'nope' as name union all select 3 as id,'' as name union all s...
阅读全文
摘要:hive的高级数据类型主要包括:数组类型、map类型、结构体类型、集合类型,以下将分别详细介绍。1)数组类型array_type:array-- 建表语句create table test.array_table(name string,age int,addr array)row format delimited fields terminated by ',' collectio...
阅读全文
摘要:上一篇解析链接如下:https://www.cnblogs.com/wcwen1990/p/9325968.html1、SQL示例1:SQL> select * from (select * from tmp1 where c >= 1) t1 left join (select * from tmp2 where b 1 and t1.e >= 2 where t1.b =CASE WH...
阅读全文
摘要:1、测试数据如下:SQL> select * from t1; a | b | c ---+----+--- 1 | 10 | 1 2 | 20 | 2 3 | 30 | 3 4 | 40 | 4 5 | 50 | 5 6 | 60 | 6(6 rows)SQL> select * from t2; a | b | d ---+----+--- 1 | 10 | 1 2 |...
阅读全文
摘要:1、hive取得当前日期时间:1.1) 取得当前日期:select current_date();1.2) 取得当前日期时间:select current_timestamp();1.3) hive取得当前时间戳:select unix_timestamp();1.4) 时间戳转日期:select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');1....
阅读全文
摘要:1、测试数据: SQL> select * from dept; DEPTNO DNAME LOC 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON SQL> select * from e
阅读全文
摘要:转自:http://blog.csdn.net/wguangliang/article/details/50167283 要求:按照课程分组,查找每个课程最高的两个成绩。 数据文件如下: 第一列no为学号,第二列course为课程,第三列score为分数 [plain] view plain cop
阅读全文
摘要:层次查询是一种确定数据行间关系的一种操作手段。层次查询遍历的是一个树形结构。基本语法如下,以下语法嵌入到标准SQL中即可达到层次查询的目的: level,... ...【注释:伪列,用于select子句中,根据数据所处的层次结构自动层次编号】 connect by [nocycle] prior 连
阅读全文
摘要:测试数据: SQL> select * from sscore; NAME SCORE aa 99 bb 56 cc 56 dd 77 ee 78 ff 76 gg 78 ff 50 8 rows selected 针对以上表,需要按成绩进行排序,从而取得名次信息: 实现方法一:分析函数 SQL>
阅读全文
摘要:题目: 一组通话记录(总共500万条):ID 主叫号码 被叫号码 通话起始时间 通话结束时间 通话时长1 98290000 0215466546656 2007-02-01 09:49:53.000 2007-02-01 09:50:16.000 232 98290000 021546654666
阅读全文
摘要:准备测试数据: create table test01( groupid number, a number, b number, c number ); insert into test01 values(1,2,3,4); insert into test01 values(1,2,6,4); i
阅读全文
摘要:在进行报表开发时,很多时候会遇到行列转换操作,很对开发人员针对于SQL级别行列转换操作一直不甚理解,今天正好抽空对其进行了一些简单的总结。这里主要列举3种可以实现SQL行列转换的方法,包括通用SQL解法以及Oracle支持解法。 一、测试数据 测试表依旧采用Oracle经典的scott模式下的dep
阅读全文