-- find gender percentage select Gender, CAST(ROUND(CAST(COUNT(*) as float)/CAST((select COUNT(*) from GenderData) as float) * 100, 2) as varchar)+'%' as GenderPercent from GenderData group by Gender -- select Gender, SUM(CASE WHEN Gender = 'Male' THEN 1 ELSE 0 END) as MaleCount, SUM(CASE WHEN Gender = 'Female'THEN 1 ELSE 0 END) as FemaleCount from GenderData group by Gender;
proportion % select Name, CAST(CAST(CAST(SUM(Prize) as decimal)/CAST((select SUM(Prize) from ProportionData) as decimal) * 100 as decimal(10, 2)) as varchar) +'%' as Proportion_Percent from ProportionData group by Name
select Name, CAST(CAST(CAST(SUM(Prize) as decimal)/CAST((select SUM(Prize) from ProportionData) as decimal) * 100 as decimal(10, 2)) as varchar) +'%' as Proportion_Percent from ProportionData group by Name -- ;with cte_temp as ( select Name, Prize, SUM(Prize) OVER (ORDER BY Name ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as total from ProportionData ) select Name, CAST(ROUND(cast(Prize as float)/cast(total as float) * 100, 2) as varchar)+'%' as proportion from cte_temp
-- find gender percentage
select
Gender, CAST(ROUND(CAST(COUNT(*) as float)/CAST((select COUNT(*) from GenderData) as float) * 100, 2) as varchar)+'%' as GenderPercent
from GenderData
group by Gender
--
select
Gender,
SUM(CASE WHEN Gender = 'Male' THEN 1 ELSE 0 END) as MaleCount,
SUM(CASE WHEN Gender = 'Female'THEN 1 ELSE 0 END) as FemaleCount
from GenderData
group by Gender;
proportion %
select
Name,
CAST(CAST(CAST(SUM(Prize) as decimal)/CAST((select SUM(Prize) from ProportionData) as decimal) * 100 as decimal(10, 2)) as varchar) +'%' as Proportion_Percent
from ProportionData
group by Name
select
Name,
CAST(CAST(CAST(SUM(Prize) as decimal)/CAST((select SUM(Prize) from ProportionData) as decimal) * 100 as decimal(10, 2)) as varchar) +'%' as Proportion_Percent
from ProportionData
group by Name
--
;with cte_temp as
(
select
Name,
Prize,
SUM(Prize) OVER (ORDER BY Name ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as total
from ProportionData
)
select Name, CAST(ROUND(cast(Prize as float)/cast(total as float) * 100, 2) as varchar)+'%' as proportion from cte_temp
please share the DDL and DML scripts also
Added