Skip to Content
Presto实战
book

Presto实战

by Matt Fuller, Manfred Moser, Martin Traverso
March 2021
Intermediate to advanced
265 pages
6h 50m
Chinese
Posts & Telecom Press
Content preview from Presto实战
140
8
8.13
 
ORDER BY
子句和
LIMIT
子句
ORDER BY
子句含有用于对结果进行排序的表达式。该子句可以包含多个表达式,是从左到右
进行计算的。通常,当左边的表达式计算结果中出现重复值时,会使用右边的表达式来确定
顺序。表达式可以指定排序顺序为升序(例如
A
~
Z
1~100
)或降序(例如
Z
~
A
100~1
)。
LIMIT
子句用于限制返回的行数,并且可以与
ORDER BY
子句结合使用来查找有序集的前
N
个结果:
SELECT mktsegment,
round(sum(acctbal), 2) AS acctbal_per_mktsegment
FROM tpch.sf1.customer
GROUP BY mktsegment
HAVING sum(acctbal) > 0
ORDER BY acctbal_per_mktsegment DESC
LIMIT 1;
mktsegment | acctbal_per_mktsegment
------------+------------------------
MACHINERY | 19851.2
(1 row)
通常情况下,
Presto
能够将
ORDER BY
LIMIT
作为一个组合步骤来优化执行,而不是分开
执行。
LIMIT
可以不使用
ORDER BY
子句,但大多数情况下它们是一起使用的。原因是
SQL
标准
(继而也是
Presto
的标准)并不保证结果的顺序
。这就意味着,在没有
ORDER BY
子句的情
况下使用
LIMIT ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
机器学习流水线实战

机器学习流水线实战

Hannes Hapke, Catherine Nelson

Publisher Resources

ISBN: 9787115560056