在select和group by one column中包含多列的sql配置单元查询

mwngjboj  于 2021-05-27  发布在  Hadoop
关注(0)|答案(1)|浏览(361)

我有下面的样本图像的数据集和预期的结果。在拥有10亿条记录的数据集中,实现这种结果的最佳方法是什么。我们应该使用中间临时表还是in1查询。
req:- get 表中有2条以上记录的sns的所有记录,仅显示价格为100的记录

CREATE TABLE test(
  `sn` string, 
  `itemA` string, 
  `itemB` string, 
  `price` int)

insert into table test values ('1','A','D',100),('1','B','E',100),('1','C','F',200),('2','A','D',100),('2','C','F',200);
weylhg0b

weylhg0b1#

使用窗口功能:

select t.*
from (select t.*, count(*) over (partition by sn) as cnt
      from test t
     ) t
where cnt > 2 and price = 100;

相关问题