- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在计算要在饼图中显示的内容。我想仅显示实际投资类型的最高 6 个计数,其余的作为投资类型显示为“其他”。
SELECT i.investment_type AS investmentType,
COUNT(*) AS investmentCount
FROM investment i,
vertical v
WHERE v.vertical_name = i.investment_type
AND v.type = 'STR'
AND i.status_funding = 'o'
GROUP
BY i.investment_type
ORDER
BY investmentCount desc
上面的查询给了我一个结果
通过将 limit 6
添加到我得到的查询中
我需要的是另一行投资类型“其他”和投资计数“7”。
最佳答案
您可能想尝试以下操作:
SELECT i.investment_type as investmentType,COUNT(*) as investmentCount FROM investment i,vertical v
WHERE v.vertical_name =i.investment_type AND v.type='STR' AND i.status_funding ='o'
group by i.investment_type order by investmentCount desc
limit 6
UNION
SELECT "others" as investmentType, SUM(othersInvestmentCount) as investmentCount FROM (
SELECT COUNT(*) as othersInvestmentCount FROM investment i,vertical v
WHERE v.vertical_name =i.investment_type AND v.type='STR' AND i.status_funding ='o'
group by i.investment_type order by investmentCount desc
limit 6, 4294967296
)
我没有测试这个查询,如果您发现语法问题,可以编辑它。涉及三个实际查询,但它不应该太慢(如果不需要更快,则无需尝试更快)。
我假设您的数据库中的记录少于 2^32 条,这对于 MySQL 数据库来说似乎是一个非常合理的假设(但如果您觉得不安全,只需将其替换为 2^64)。
关于mysql - 限制计数,其余为 "Others",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26114510/
解释起来有点复杂,但却是一个非常常见的用例。 我的页面上有此字段: 其中的所有选项都有名称,包括这个: Other 我还有一个文本输入,仅当用户选择“其他”时才需要。 这是我的精简验证代码: $th
我想对我表中的一个项目进行 GROUP BY,该项目具有相关的货币值(value)。我可以用百分比来计算,但是列表中的项目通常太多(太多而无用,例如在图表中)。因此,我想将那些对总数的贡献小于 5%
我有一个组合框来显示我的数据库中的数据(varchar)。数据总是“1,2,3,4, others”,当我显示它排序的数据时: 1 10 11 12 2 3 4 All Others 如何使下拉菜单看
我需要制作一份网站访问统计报告。在报告中用户可以指定各种参数。到目前为止,每当他们为参数选择值时,就会添加一个附加的 WHERE 子句,如下所示: SELECT id_browser, COUNT(v
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 8 年前。 Improv
我有一个包含一个维度和一个指标的表格: name metric A 4 A 9 B 27 C 9 D 6 我想按维度分组,然后将结果的长尾分组到“其他”或“其余数据”标签中。 例如
我正在尝试将 lighttpd 访问日志文件的读取权限授予同一系统上的普通用户。目前的权限是: -rw-r--r-- 1 www-data www-data 211K Feb 28 11:27/var
我在 Data Studio 中有一个饼图,如下所示: 正如您从甜甜圈中看到的那样,有我不想在那里看到的“其他”切片,我想自定义标签以显示“python (88%)”。 任何人都可以分享您的专业知识并
我很少使用因子,通常认为它们易于理解,但我经常对特定操作的细节感到模糊。目前,我正在编码/折叠类别,几乎没有观察到“其他”,并且正在寻找一种快速的方法来做到这一点 - 我有一个可能有 20 个级别的变
我正在尝试拉出我的Gmail联系人,这样我就可以自动完成我在Gmail中拥有的3,000多个联系人。使用Google Contacts Data API,我可以获得(1)默认联系人和(2)组的列表。
我可以使用以下选项分解 Google 饼图中的第一个切片。 var options = { title: 'My Daily Activities',
我想在选中“其他”复选框时显示文本框。 我尝试过下面的脚本。但这不起作用。使用组合框时很好。 $('input[name=ctrl_CheckedList_qflht]').on('click',(
我可以从我的Facebook页面获取图像,没有问题,但是只有页面管理员上传的图像。 https://graph.facebook.com/tofinobc/photos/ 我要获取的是“其他人”上传的
我希望有人能指出我在哪里出错了,但我在过去的 30 分钟里一直在看这个,但没有得到任何结果。 我有一个填充了数据的临时表,前端应用程序无法为我执行任何逻辑,所以请原谅表中丑陋的 case 语句逻辑。
我的表单中有一个下拉列表,我想让用户选择“其他”选项,这样他就可以在文本框中插入一个值,而不是下拉列表中的值。这可能吗? field($model, 'institution')->dropDownL
我有一个像这样的 SelectListItems 列表: List test = new List { new SelectListItem { Text="aaa", Value ="1"}
字体Calibre有Light、Light Italic、Italic、Regular、Bold和Bold Italic版本。 使用示例:Font font = new Font("Calibre",
我正在计算要在饼图中显示的内容。我想仅显示实际投资类型的最高 6 个计数,其余的作为投资类型显示为“其他”。 SELECT i.investment_type AS investmentType,
我有一个形状为 (600,000 * 33) 的数据框其中一列,我们称之为“名称”,有超过 2000 个唯一值。我已使用以下代码对列进行排序: got.groupby('name').size().s
我有一个下拉列表,用户可以在其中选择返回原因。下拉菜单有“其他”选项,它将显示另一个文本框以插入另一个信息。如果用户选择“其他”选项,我已经获得了从下拉列表中保存值的代码,但不是文本框中的值。谢谢!
我是一名优秀的程序员,十分优秀!