calculate percentage of two column value and store into other column
-
my query like this
cte3_persen (per) as
(select ((cte1.totalcount/cte2.TotaCount)* 100 )
from cte1,cte2)i am creating one new cte table shown above
from that value '2'coming from cte1.totalcount and value '500' coming from cte2.TotaCount
i want percentage of those value it should be in 0.00% format
i want ans of per from cte3_persen table is =0.40%
please help some one -
my query like this
cte3_persen (per) as
(select ((cte1.totalcount/cte2.TotaCount)* 100 )
from cte1,cte2)i am creating one new cte table shown above
from that value '2'coming from cte1.totalcount and value '500' coming from cte2.TotaCount
i want percentage of those value it should be in 0.00% format
i want ans of per from cte3_persen table is =0.40%
please help some oneWhat are your data types for the
TotalCount
variables? are they ofDecimal
type? if so then have a look at thisDECLARE @value1 DECIMAL(18,2)
DECLARE @value2 DECIMAL(18,2)SET @value1 = 2
SET @value2 = 500SELECT (@value1 / @value2)*100
SELECT CAST((@value1 / @value2)*100 AS DECIMAL(18,2))Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
What are your data types for the
TotalCount
variables? are they ofDecimal
type? if so then have a look at thisDECLARE @value1 DECIMAL(18,2)
DECLARE @value2 DECIMAL(18,2)SET @value1 = 2
SET @value2 = 500SELECT (@value1 / @value2)*100
SELECT CAST((@value1 / @value2)*100 AS DECIMAL(18,2))Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
totalcount is int type
-
totalcount is int type
is that the same for TotalCount from the second CTE?
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
my query like this
cte3_persen (per) as
(select ((cte1.totalcount/cte2.TotaCount)* 100 )
from cte1,cte2)i am creating one new cte table shown above
from that value '2'coming from cte1.totalcount and value '500' coming from cte2.TotaCount
i want percentage of those value it should be in 0.00% format
i want ans of per from cte3_persen table is =0.40%
please help some oneSounds like you want to round your result to 2 decimal places before dividing by 100 SELECT (2/500)* 100 AS not_rounded, (round(2/500,2))* 100 AS rounded from dual; returns NOT_ROUNDED ROUNDED ----------- ------- 0.4 0
Regrads