问题描述
我有一个像这样的列表:
态度|准时性
-------------------------------
促进性|始终
粗鲁|始终
促进性|一般
粗鲁|从不
(注意:无差异"可能是态度"的可能值)
我想要这样的结果:
值|否| PERCENT
--------------------------------
促进性| 2 | 50%
淡泊| 0 | 0%
粗鲁| 2 | 50%
永远2 | 50%
平均1 | 25%
永不| 1 | 25%
I have a column table like this:
ATTITUDE | PUNCTUALITY
-------------------------------
Facilitative| Always
Rude | Always
Facilitative| Average
Rude | Never
(Note: ''Indifferent'' can be a possible value of ATTITUDE)
I want result like this:
VALUES | NO | PERCENT
--------------------------------
Facilitative | 2 |50%
Indifferent |0 | 0%
Rude | 2 |50%
Always | 2 | 50%
Average | 1 | 25%
Never | 1 | 25%
推荐答案
SELECT a.Attitude,
COUNT(*),
COUNT(*) / (SELECT COUNT(*) FROM YourTable) AS Percent
FROM PossibleValues a left outer join YourTable b on a.attitude = b.attitude
GROUP BY a.Attitude
这篇关于列值计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!