基本操作:

查询:

SELECT [ALL | DISTINCT] select_expr, select_expr, ...
FROM table_reference
[WHERE where_condition]
[GROUP BY col_list]
[ORDER BY order_condition]
[DISTRIBUTE BY distribute_condition [SORT BY sort_condition] ]
[LIMIT number] 

更新:

INSERT OVERWRITE|INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)] [(col1,col2 ...)]
select_statement
FROM from_statement;

表关联:

join_table:
table_reference join table_factor [join_condition]
| table_reference {left outer|right outer|full outer|inner} join table_reference join_condition
table_reference:
table_factor
| join_table
table_factor:
tbl_name [alias]
| table_subquery alias
| ( table_references )
join_condition:
on equality_expression ( and equality_expression )

演示内容:

使用DML:

*查询已有数据

*使用表连接查询数据

*覆盖更新

*追加更新

//上传演示数据
odps@ sdrtest>tunnel upload /root/.odpscmd/t_people.txt t_people;
//查看演示数据
odps@ sdrtest>select * from t_people;
+------------+------+
| id | name |
+------------+------+
| 1 | Michael Jordan |
| 2 | Angela Dorthea Merkel |
| 3 | Bruce Willis |
| 4 | Kim Kardashian |
| 5 | Jhon Knight |
| 6 | Maria Sharapova |
| 7 | Chiang Kai-shek |
| 8 | Jennifer Aniston |
| 9 | David Beckham |
| 10 | Dragon Lady |
+------------+------+
odps@ sdrtest>select count(*),id from t_people group by id having count(*) > 0; ID = 20190414051444876gfk3c692
Job Queueing.
----------------------------------------------------------------------------------------------
STAGES STATUS TOTAL COMPLETED RUNNING PENDING BACKUP
M1_job_0 ................. TERMINATED 1 1 0 0 0
----------------------------------------------------------------------------------------------
STAGES STATUS TOTAL COMPLETED RUNNING PENDING BACKUP----------
M1_job_0 ................. TERMINATED 1 1 0 0 0----------------------------------------------------------------------------------
R2_1_job_0 ............... TERMINATED 1 1 0 0 0
----------------------------------------------------------------------------------------------
STAGES: 02/02 [==========================>>] 100% ELAPSED TIME: 8.17 s
----------------------------------------------------------------------------------------------
Summary:
resource cost: cpu 0.00 Core * Min, memory 0.00 GB * Min
inputs:
sdrtest.t_people: 10 (776 bytes)
outputs:
Job run time: 5.000
Job run mode: fuxi job
Job run engine: execution engine
M1:
instance count: 1
run time: 3.000
instance time:
min: 0.000, max: 0.000, avg: 0.000
input records:
TableScan1: 10 (min: 10, max: 10, avg: 10)
output records:
StreamLineWrite1: 10 (min: 10, max: 10, avg: 10)
writer dumps:
StreamLineWrite1: (min: 0, max: 0, avg: 0)
R2_1:
instance count: 1
run time: 5.000
instance time:
min: 0.000, max: 0.000, avg: 0.000
input records:
StreamLineRead1: 10 (min: 10, max: 10, avg: 10)
output records:
AdhocSink1: 10 (min: 10, max: 10, avg: 10)
reader dumps:
StreamLineRead1: (min: 0, max: 0, avg: 0) +------------+------------+
| _c0 | id |
+------------+------------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 1 | 6 |
| 1 | 7 |
| 1 | 8 |
| 1 | 9 |
| 1 | 10 |
+------------+------------+
//使用表连接查询数据
odps@ sdrtest>select t1.* from t_people t1 join t_people t2 on t1.id=t2.id; ID = 20190414052009767gcpxmnim Job Queueing.
----------------------------------------------------------------------------------------------
STAGES STATUS TOTAL COMPLETED RUNNING PENDING BACKUP
M1_job_0 ................. TERMINATED 1 1 0 0 0
----------------------------------------------------------------------------------------------
STAGES STATUS TOTAL COMPLETED RUNNING PENDING BACKUP----------
M1_job_0 ................. TERMINATED 1 1 0 0 0----------------------------------------------------------------------------------
J2_1_job_0 ............... TERMINATED 1 1 0 0 0
----------------------------------------------------------------------------------------------
STAGES: 02/02 [==========================>>] 100% ELAPSED TIME: 8.56 s
----------------------------------------------------------------------------------------------
Summary:
resource cost: cpu 0.00 Core * Min, memory 0.00 GB * Min
inputs:
sdrtest.t_people: 10 (776 bytes)
outputs:
Job run time: 6.000
Job run mode: fuxi job
Job run engine: execution engine
M1:
instance count: 1
run time: 3.000
instance time:
min: 0.000, max: 0.000, avg: 0.000
input records:
TableScan1: 10 (min: 10, max: 10, avg: 10)
output records:
StreamLineWrite1: 10 (min: 10, max: 10, avg: 10)
StreamLineWrite2: 10 (min: 10, max: 10, avg: 10)
writer dumps:
StreamLineWrite1: (min: 0, max: 0, avg: 0)
StreamLineWrite2: (min: 0, max: 0, avg: 0)
J2_1:
instance count: 1
run time: 6.000
instance time:
min: 0.000, max: 0.000, avg: 0.000
input records:
StreamLineRead1: 10 (min: 10, max: 10, avg: 10)
StreamLineRead2: 10 (min: 10, max: 10, avg: 10)
output records:
AdhocSink1: 10 (min: 10, max: 10, avg: 10)
reader dumps:
StreamLineRead1: (min: 0, max: 0, avg: 0)
StreamLineRead2: (min: 0, max: 0, avg: 0) +------------+------+
| id | name |
+------------+------+
| 1 | Michael Jordan |
| 2 | Angela Dorthea Merkel |
| 3 | Bruce Willis |
| 4 | Kim Kardashian |
| 5 | Jhon Knight |
| 6 | Maria Sharapova |
| 7 | Chiang Kai-shek |
| 8 | Jennifer Aniston |
| 9 | David Beckham |
| 10 | Dragon Lady |
+------------+------+
//创建新表用于演示追加更新:
odps@ sdrtest>create table t_people_new like t_people;
odps@ sdrtest>read t_people_new;
+------------+------------+
| id | name |
+------------+------------+
+------------+------------+
odps@ sdrtest>insert into table t_people_new select * from t_people;
//查看新建的表内写入的数据:
odps@ sdrtest>read t_people_new
>;
+------------+------------+
| id | name |
+------------+------------+
| 1 | Michael Jordan |
| 2 | Angela Dorthea Merkel |
| 3 | Bruce Willis |
| 4 | Kim Kardashian |
| 5 | Jhon Knight |
| 6 | Maria Sharapova |
| 7 | Chiang Kai-shek |
| 8 | Jennifer Aniston |
| 9 | David Beckham |
| 10 | Dragon Lady |
+------------+------------+
//演示追加更新 <into>
odps@ sdrtest>insert into table t_people_new select * from t_people;
Job Queueing.
----------------------------------------------------------------------------------------------
STAGES STATUS TOTAL COMPLETED RUNNING PENDING BACKUP
M1_job_0 ................. TERMINATED 1 1 0 0 0
----------------------------------------------------------------------------------------------
STAGES: 01/01 [==========================>>] 100% ELAPSED TIME: 5.26 s
----------------------------------------------------------------------------------------------
Summary:
resource cost: cpu 0.00 Core * Min, memory 0.00 GB * Min
inputs:
sdrtest.t_people: 10 (776 bytes)
outputs:
sdrtest.t_people_new: 10 (776 bytes)
Job run time: 3.000
Job run mode: fuxi job
Job run engine: execution engine
M1:
instance count: 1
run time: 3.000
instance time:
min: 0.000, max: 0.000, avg: 0.000
input records:
TableScan1: 10 (min: 10, max: 10, avg: 10)
output records:
TableSink1: 10 (min: 10, max: 10, avg: 10) OK
odps@ sdrtest>read t_people_new;
+------------+------------+
| id | name |
+------------+------------+
| 1 | Michael Jordan |
| 2 | Angela Dorthea Merkel |
| 3 | Bruce Willis |
| 4 | Kim Kardashian |
| 5 | Jhon Knight |
| 6 | Maria Sharapova |
| 7 | Chiang Kai-shek |
| 8 | Jennifer Aniston |
| 9 | David Beckham |
| 10 | Dragon Lady |
| 1 | Michael Jordan |
| 2 | Angela Dorthea Merkel |
| 3 | Bruce Willis |
| 4 | Kim Kardashian |
| 5 | Jhon Knight |
| 6 | Maria Sharapova |
| 7 | Chiang Kai-shek |
| 8 | Jennifer Aniston |
| 9 | David Beckham |
| 10 | Dragon Lady |
+------------+------------+ //演示覆盖更新 <overwrite>
odps@ sdrtest>insert overwrite table t_people_new select * from t_people; ----------------------------------------------------------------------------------------------
STAGES STATUS TOTAL COMPLETED RUNNING PENDING BACKUP
M1_job_0 ................. TERMINATED 1 1 0 0 0
----------------------------------------------------------------------------------------------
STAGES: 01/01 [==========================>>] 100% ELAPSED TIME: 5.24 s
----------------------------------------------------------------------------------------------
Summary:
resource cost: cpu 0.00 Core * Min, memory 0.00 GB * Min
inputs:
sdrtest.t_people: 10 (776 bytes)
outputs:
sdrtest.t_people_new: 10 (776 bytes)
Job run time: 3.000
Job run mode: fuxi job
Job run engine: execution engine
M1:
instance count: 1
run time: 3.000
instance time:
min: 0.000, max: 0.000, avg: 0.000
input records:
TableScan1: 10 (min: 10, max: 10, avg: 10)
output records:
TableSink1: 10 (min: 10, max: 10, avg: 10) OK
odps@ sdrtest>read t_people_new;
+------------+------------+
| id | name |
+------------+------------+
| 1 | Michael Jordan |
| 2 | Angela Dorthea Merkel |
| 3 | Bruce Willis |
| 4 | Kim Kardashian |
| 5 | Jhon Knight |
| 6 | Maria Sharapova |
| 7 | Chiang Kai-shek |
| 8 | Jennifer Aniston |
| 9 | David Beckham |
| 10 | Dragon Lady |
+------------+------------+
odps@ sdrtest>

  

others....

ODPS SQL <for 数据操作语言DML>的更多相关文章

  1. ODPS SQL <for 数据定义语言 DDL>

    数据定义语言:(DDL) 建表语句: CREATE TABLE [IF NOT EXISTS] table_name [(col_name data_type [COMMENT col_comment ...

  2. MySQL之数据定义语言(DDL)

    写在前面 本文中 [ 内容 ] 代表啊可选项,即可写可不写. SQL语言的基本功能介绍 SQL是一种结构化查询语言,主要有如下几个功能: 数据定义语言(DDL):全称Data Definition L ...

  3. <MySQL>入门三 数据定义语言 DDL

    -- DDL 数据定义语言 /* 库和表的管理 一.库的管理:创建.修改.删除 二.表的管理:创建.修改.删除 创建:create 修改:alter 删除:drop */ 1.库的管理 -- 库的管理 ...

  4. 30441数据定义语言DDL

    数据定义:指对数据库对象的定义.删除和修改操作. 数据库对象主要包括数据表.视图.索引等. 数据定义功能通过CREATE.ALTER.DROP语句来完成. 按照操作对象分类来介绍数据定义的SQL语法. ...

  5. SQL语句整理(二) 数据定义语言DDL

    前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...

  6. oracle 数据定义语言(DDL)语法

    DDL语言包括数据库对象的创建(create).删除(drop)和修改(alter)的操作 1.创建表语法 create table table_name( column_name datatype  ...

  7. 【MySQL笔记】数据定义语言DDL

    1.创建基本表   create table <表名> (<列名><数据类型>[列级完整性约束条件]                                 ...

  8. SQLite基础-4.数据定义语言(DDL)

    目录 一.创建数据库 1. 创建方式 2. 数据库命名规范 二. 创建表 1. 基本用法 2. 数据表命名规范 3. 字段命名规范 三. 删除表 一.创建数据库 1. 创建方式 在第二章中我们讲了如何 ...

  9. MySQL SQL DLL (数据定义语言)

    CREATE CREATE DATABASE CREATE DATABASE 用于创建数据库 CREATE DATABASE new_database_name; CREATE TABLE CREAT ...

随机推荐

  1. 03_安装vsftp服务器

    1 安装vsftpd组件 [root@bogon ~]# yum -y install vsftpd 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. 2 添 ...

  2. JAVA常用设计模式(一、抽象工厂模式)

    抽象工厂模式 抽象工厂模式(Abstract Factory Pattern)是围绕一个超级工厂创建其他工厂.该超级工厂又称为其他工厂的工厂.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最 ...

  3. 【ShareCode】不错的技术文章 -- 如何使用异或(XOR)运算找到数组中缺失的数?

    如何使用异或(XOR)运算找到数组中缺失的数? 今天给大家分享一篇关于使用XOR(异或)运算找到数组中缺失的数的问题. 在一次Javascript面试中,有这么一个问题: 假设有一个由0到99(包含9 ...

  4. 通过父元素的hover控制子元素的显示

    .searbar_content_box:hover .searchBar_checked_detail_box{ display:block}

  5. export 和import使用

    在JavaScript ES6中,export与export default均可用于导出常量.函数.文件.模块等,你可以在其它文件或模块中通过import+(常量 | 函数 | 文件 | 模块)名的方 ...

  6. #电脑磁盘分区#新买的电脑一般只有C盘或者C盘和D盘,怎么加多几个盘呢

    新买的电脑一般只有C盘或者C盘和D盘,怎么加多几个盘呢 鼠标右键点击桌面我的电脑选择管理 进入计算机管理.选择磁盘管理 若桌面没有我的电脑,可按win+x键,在快捷菜单栏中点击磁盘管理 通过以上两种w ...

  7. spring redis 注解实现缓存机制

    1.xml配置 <bean id="poolConfigTax" class="redis.clients.jedis.JedisPoolConfig"& ...

  8. 一 Struts框架(上)

    Struts2 是基于MVC的WEB框架 经过六年多的发展,Struts1已经成为了一个高度成熟的框架,不管是稳定性还是可靠性都得到了广泛的证明.市场占有率超过20%,拥有丰富的开发人群,几乎已经成为 ...

  9. Fiddler: 如何抓取HTTPS协议的网页

    作者:韦玮  转载请注明出处 Fiddler默认只能抓取HTTP协议的网页,不能抓取HTTPS协议的网页,而我们很多时候,都需要抓HTTPS协议的网页,比如抓淘宝数据等.今天,韦玮老师会为大家讲解如何 ...

  10. 问题 Windows7VMware14安装虚拟机时出现 此主机不支持虚拟化实际模式。需要具备 Intel“VMX 不受限客户机”功能才能在 Intel 处理器上运行此虚拟机。 模块“CPUIDEarly”启动失败。

    问题 Windows7VMware14安装虚拟机时出现 此主机不支持虚拟化实际模式.需要具备 Intel“VMX 不受限客户机”功能才能在 Intel 处理器上运行此虚拟机. 模块“CPUIDEarl ...