Sql 配置单元-相关值之和

Sql 配置单元-相关值之和,sql,amazon-web-services,count,presto,amazon-athena,Sql,Amazon Web Services,Count,Presto,Amazon Athena,我在AWS Athena上工作,过滤负载平衡器日志。我已经创建了下表并将日志导入表中 CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs ( request_timestamp string, elb_response_code string, url string, ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROP

我在AWS Athena上工作,过滤负载平衡器日志。我已经创建了下表并将日志导入表中

CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs  (
  request_timestamp string,   
  elb_response_code string,    
  url string, 
   ) 

ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
         'serialization.format' = '1','input.regex' = '([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:\-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\" (\"[^\"]*\") ([A-Z0-9-]+) ([A-Za-z0-9.-]*)$' )
LOCATION 's3://athena-examples/elb/raw/';
现在我想计算200个,400个和500个响应。所以我执行了下面的查询

SELECT distinct(elb_response_code),
         count(url) AS count
FROM elb_logs
GROUP BY  elb_response_code
它工作了,但返回了所有响应,如下所示

**response  count**
401   1270
201   1369
422   342
200   3568727
400   1221
404   444
304   10435
413   3
206   30
500   1542
我想对所有400401044413422求和,对2xx、3xx和5xx求和,结果应该是4xx和(400401044413422)


假设所有代码都有3个字符长

select      substr (elb_response_code,1,1) || 'xx' as elb_response_code_prefix
           ,count(*)                               as cnt

from        elb_logs

group by    1
这里有一个更通用的解决方案

select      rpad (substr (elb_response_code,1,1),length(elb_response_code),'x') 
                      as elb_response_code_prefix
           ,count(*)  as cnt

from        elb_logs

group by    1

假设所有代码都有3个字符长

select      substr (elb_response_code,1,1) || 'xx' as elb_response_code_prefix
           ,count(*)                               as cnt

from        elb_logs

group by    1
这里有一个更通用的解决方案

select      rpad (substr (elb_response_code,1,1),length(elb_response_code),'x') 
                      as elb_response_code_prefix
           ,count(*)  as cnt

from        elb_logs

group by    1

谢谢,它的工作,这是可能的,以显示与xx的响应代码值。比如结果窗口中的2xx,3xx?现在是2,3,4,5,不客气。请参见更新的解决方案。这有很多变化。谢谢,它的工作,这是可能的,以显示与xx的响应代码值。比如结果窗口中的2xx,3xx?现在是2,3,4,5,不客气。请参见更新的解决方案。这方面有很多变化。