0
我目前的查詢返回的總人數在各民族不如預期,例如:如何獲得總數?
Name | Count
----------------------
White | 22
Asian | 15
Black | 12
等等但是我想補充一個THRID列返回各族羣爲總數的百分比,我會怎麼做呢?
SELECT
eo.EthnicOriginName,
ISNULL(e.Number, '')
--CAST(e.Number AS FLOAT)/CAST(COUNT(e.intEthnicOriginID) AS FLOAT) * 100
FROM
tblEthnicOrigin eo
INNER JOIN tblPerson p ON p.intEthnicOriginID = eo.EthnicOriginID
LEFT JOIN (SELECT intEthnicOriginID, COUNT(p.intPersonID) [Number]
FROM tblPerson p
INNER JOIN tblClient c on c.intPersonID = p.intPersonID
GROUP BY intEthnicOriginID) e on e.intEthnicOriginID = eo.EthnicOriginID
GROUP BY
eo.EthnicOriginName, e.Number
您正在使用哪些DBMS? (MySQL或SQL Server或Oracle或...) –
我正在使用SQL Server – user3027864
然後戈登的答案應該是你在找什麼。 –