You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 18:01:16