I have a select statement with a distinct count and I need to divide the result of the select count with a number . How can I do it? I have for example:
select distinct count(profile_entity_name)
from table_name
where visit_id like 'JWM%' and profile_entity_name not in ('JWM 2.0 COM','JWM 2.0 MASTER')
and it gives the result 2000 I want to divide the 2000 with 130 for example on the fly
How can I do it? I tried the whole select with the division at the end '/130' and it doesn't work
CodePudding user response:
Use of distinct
before count
has no meaning. Perhaps you want to count distinct profile_entity_name
, So you can try this :
select count(distinct profile_entity_name) / 130 from ....
CodePudding user response:
As an complement to Md. Suman Kabir's Answer, if you want the select to return the exact division, just cast the "count" function and the divisor number as float, like this:
select cast(count(distinct profile_entity_name) as float) / cast(130 as flot) from table_name
CodePudding user response:
save your result and divide with 130
select TB1.[total count]/130 from (select distinct count(profile_entity_name)as[total count]
from table_name
where visit_id like 'JWM%' and profile_entity_name not in ('JWM 2.0 COM','JWM 2.0 MASTER') ) as TB1