spark sql配置单元sql查询具有多个limit子句

x4shl7ld  于 2021-06-29  发布在  Hive
关注(0)|答案(2)|浏览(684)

我对配置单元和sparksql技术比较陌生,我在sparksql中尝试过limit子句。但是它只支持从零开始到那个特定限制的特定限制。但是我想从一个特定的起点到一个特定的终点检索行。你能不能请任何人建议一个方法来实现这一点。

Query1 :: SELECT * FROM `Emp` LIMIT 10;  - this query supports in both sql and spark sql

但是

Query2 :: SELECT * FROM `Emp` LIMIT 10,20;  - to retrive rows from 10 to 20 supports in sql, but not in spark sql.
cmssoen2

cmssoen21#

你可以用 ROW_NUMBER 在hql中

SELECT *,ROW_NUMBER over (Order by id)  as rowid FROM `Emp`
where rowid > 10 and rowid <=20;
ubof19bj

ubof19bj2#

尝试修改左连接:

SELECT a.*
FROM
(SELECT * FROM `Emp` LIMIT 20) a
LEFT JOIN
(SELECT * FROM `Emp` LIMIT 10) b
ON a.primary_key=b.primary_key
WHERE b.primary_key IS NULL

相关问题