如何获取SQL中特定分组中的每条记录(希望通过索引)?

时间:2017-05-11 10:28:33

标签: sql impala

我有一个Impala查询,使用group by on many colums将数百万条记录聚合成组

select col1, col3, col5, col7, col23 col24, count(*) as count 
from my_table 
group by col1, col3, col5, col7, col23 col24

结果:

col1, col3, col5, col7, col23 col24, count
John, Michaels, USD, ABC, 123, AA, 1243560969
Ryan, Jones, USD, FCC, 101, BB, 5043855
James, Gerrity, YEN, FCC, 102, BA, 37876899

如何获取SQL中特定分组中的每条记录(希望通过索引)?

我正在寻找像

这样的东西
SELECT * 
FROM GROUP 3 IN (
  select col1, col3, col5, col7, col23 col24, count(*) as count 
  from y_table 
  group by col1, col3, col5, col7, col23 col24, count
)

你认为这是可能的吗?任何建议都非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试:

select col1, col3, col5, col7, col23, col24,
 count(*) as cnt, some_function_to_form_groups as grp 
from my_table 
group by col1, col3, col5, col7, col23, col24 
having grp = 3

some_function_to_form_groups可以left(col1,1) {or equivalent}获得缩写等。