如何确定 Oracle 中列值的分布?
例如,如果我有一列代表 Y
或 N
标志,则 Y
的百分比是多少,的百分比是多少N?我知道我可以编写一个查询来查找每个数字,然后自己计算百分比,但我认为在 PL/SQL 中使用诸如
NTILE
。
SELECT COUNT(1), enabled_flag
FROM widgets
GROUP BY enabled_flag;
给我:
COUNT(1) | enabled_flag
123124 | Y
234234 | N
我需要:
enabled_flag | percentage
Y | 34
N | 56
有人能指出我正确的方向吗?
For example, if I have a column that represent a Y
or N
flag, what percentage is a Y
and what percentage is an N
? I know I can write a query to find each of these numbers and then calculate the percentage myself, but I figure it should be straight forward doing this in PL/SQL with analytic functions like NTILE
.
SELECT COUNT(1), enabled_flag
FROM widgets
GROUP BY enabled_flag;
Gives me:
COUNT(1) | enabled_flag
123124 | Y
234234 | N
I need:
enabled_flag | percentage
Y | 34
N | 56
Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的分析函数:
编辑...您还可以使用 RATIO_TO_REPORT 函数,这可能会使它看起来更干净或更容易维护:
Try an analytic function as such:
EDIT... you can also use the RATIO_TO_REPORT function which might make it look cleaner or easier to maintain:
这可能不是最好的方法,但我想它应该有效。
It might not be the best way, but I guess it should work.