如何在SQL中对DISTINCT COUNT的结果实时执行除法运算?
解决方法
首先你的原SQL语句存在写法错误:distinct count(profile_entity_name)的用法不正确,distinct应该放在count内部,用来对统计的列去重,正确的去重计数语法是count(distinct profile_entity_name)。
要实现将结果除以130,只需把正确的聚合表达式直接除以130即可,完整语句如下:
select count(distinct profile_entity_name) / 130 from table_name where visit_id like 'JWM%' and profile_entity_name not in ('JWM 2.0 COM','JWM 2.0 MASTER')
如果需要控制结果的精度(比如保留指定小数位数),可以用round()函数处理,示例如下:
select round(count(distinct profile_entity_name) / 130, 2) from table_name where visit_id like 'JWM%' and profile_entity_name not in ('JWM 2.0 COM','JWM 2.0 MASTER')
内容的提问来源于stack exchange,提问作者Electra
相关产品推荐
相关产品推荐

