如何根据 HiveQL 中特定列的子字符串 select 和 SQL?

How to do select based on a substring of a particular column in HiveQL and SQL?

我在 hive

中有一个 table
S.no  Age  minutes  code  
 1     10   20     75081     
 2     11   114    75080      
 3     21   104    75180     
 4     31   124    75108    
 5     10   20     75083     
 6     11   114    75180    
 7     21   104    75180    

我想编写一个 hivesql/sql 查询,根据区域(即代码的前 4 位数字)给出总说话分钟数的排名列表。 我该怎么办?我知道 SUBSTRING() 给了我所需的削减,但我无法从那里开始。

Select code, minutes as total  
from TableT   
where S.no > 1
group by code 
order by total

编辑: 基于邮政编码前 4 位的排名结果应如下所示

总代码

322(即104+114+104) 7518
154(即20+114+20) 7508
124 7510

嗯。我想你想要这个:

select substr(zip, 1, 4) as region, sum(minutes) as minutes,
       rank() over (order by sum(minutes) desc) as therank
from tableT
where s.no > 1
group by substr(zip, 1, 4)
order by minutes desc;