有人可以帮忙确定我的结果集的百分比吗,我无法在子查询中执行此操作:
SELECT
CntryCD,
Country,
SectyCD,
SecurityType,
COUNT(SecID) as SecurityCount,
concat(count(SecID)/(select count(SecID) from wca.scmst)*100, '%') as Percentage
FROM
(
select distinct
wca.region.CntryCD,
wca.region.Country,
wca.scmst.SectyCD,
secty.SecurityDescriptor as 'SecurityType',
wca.bond.SecID
from wca.bond
inner join wca.scmst on wca.bond.secid = wca.scmst.secid
inner join wca.secty on wca.scmst.sectycd = wca.secty.SectyCD
left outer join wca.scexh on wca.scmst.secid = wca.scexh.secid
left outer join wca.exchg on wca.scexh.exchgcd = wca.exchg.exchgcd
left outer join wca.region on ifnull(wca.exchg.cntrycd,'UB') = wca.region.cntrycd
where
wca.bond.actflag <> 'D'
and wca.scmst.actflag <> 'D'
and wca.scmst.statusflag <> 'I'
union
select distinct
wca.region.CntryCD,
wca.region.Country,
wca.scmst.SectyCD,
secty.SecurityDescriptor as 'SecurityType',
wca.scmst.SecID
from wca.scmst
inner join wca.sectygrp on wca.scmst.sectycd = wca.sectygrp.sectycd and 3> sectygrp.secgrpid
inner join wca.secty on wca.scmst.sectycd = wca.secty.SectyCD
left outer join wca.scexh on wca.scmst.secid = wca.scexh.secid
left outer join wca.exchg on wca.scexh.exchgcd = wca.exchg.exchgcd
left outer join wca.region on ifnull(wca.exchg.cntrycd,'UB') = wca.region.cntrycd
where
wca.scmst.actflag <> 'D'
and wca.scexh.liststatus <> 'D'
and (wca.scexh.actflag <> 'D' or wca.scexh.actflag is null)
and wca.scmst.statusflag <> 'I'
) AS T1
where
country = 'United Kingdom'
group by Country, SectyCD;
我得到以下结果集:
百分比是错误的-我正在尝试从所有行的总数中算出每行的百分比,应该是24218。例如,第一个记录计数13663/24218 * 100 = 56.4167%。预先感谢