选择具有特定值的行的百分比-SQL [英] Select percentage of rows that have a certain value - SQL

查看:68
本文介绍了选择具有特定值的行的百分比-SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在Sequel Pro中有一个这样的表:

Say I have a table like this in Sequel Pro:

SaleID    VendorID
1             A
2             C
3             E
4             C
5             D

我想找到卖方C是卖方的销售百分比。 (显然,在这种情况下为40%,但我正在处理更大的表)。我该怎么做?我当时在考虑使用 Count 函数,但是我不确定该怎么做。谢谢!

And I want to find the percentage of sales in which Vendor C was the vendor. (Obviously in this case it is 40%, but I'm working with much bigger tables). How would I do that? I was thinking something using the Count function, but I'm not sure how I would do it exactly. Thanks!

推荐答案

select sum(case when vendorID = 'C' then 1 else 0 end) * 100 / count(*)
from your_table

这篇关于选择具有特定值的行的百分比-SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆