本文介绍了列值计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的列表:

态度|准时性
-------------------------------
促进性|始终
粗鲁|始终
促进性|一般
粗鲁|从不

(注意:无差异"可能是态度"的可能值)



我想要这样的结果:

值|否| 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


这篇关于列值计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 17:50