首页 \ 问答 \ SQL获得百分比(SQL getting Percentage)

SQL获得百分比(SQL getting Percentage)

我有以下代码来计算总死亡率和按PersonType分组。 现在我想要一个列来计算每个死亡事故的百分比。 这是为每个人的类型取值并除以总死亡人数。

Select distinct persontype as PerSsonType, sum(fatalities_in_crash) as  Total_Deaths

  from [CarCrash].[Source_Data_Staging] 
group by PersonType

在此处输入图像描述


I have the following code to calculate total fatalities and group by the PersonType. Now I want to have a column that calculates the percentage of each fatalities. that is taking the value for each person type and dividing by the total fatalities.

Select distinct persontype as PerSsonType, sum(fatalities_in_crash) as  Total_Deaths

  from [CarCrash].[Source_Data_Staging] 
group by PersonType

enter image description here


原文:https://stackoverflow.com/questions/47239068
更新时间:2024-01-07 14:01

最满意答案

当我尝试上传不属于批处理的单个文档时,我收到的错误与您相同:

{
    "type": "delete",
    "id": "4e41b5a6f3d94aa4891ab8f9abca94e6"
}

但如果它是批次的一部分,它会成功:

[{
    "type": "delete",
    "id": "4e41b5a6f3d94aa4891ab8f9abca94e6"
}]

我意识到你在上面的例子中显示了一个json数组,但值得仔细检查,因为当你试图发布一个不属于数组的单个文档时,你会得到完全相同的错误。 由于他们自己的准备提交数据的文档显示了删除不是数组的一部分的部分示例(请参阅“从搜索域中删除文档”部分),这将是一个容易犯的错误。


I get the same error as you when I try to upload a single document that is not part of a batch:

{
    "type": "delete",
    "id": "4e41b5a6f3d94aa4891ab8f9abca94e6"
}

But it succeeds if it's part of a batch:

[{
    "type": "delete",
    "id": "4e41b5a6f3d94aa4891ab8f9abca94e6"
}]

I realize that you show a json array in your example above, but it is worth double-checking since you're getting the exact same error you'd get when trying to post a single document that is not part of an array. It would be an easy mistake to make since their own documentation on preparing data for submission shows a partial example where the delete is not part of an array (see the "To delete a document from a search domain" section).

相关问答

更多
  • 当我尝试上传不属于批处理的单个文档时,我收到的错误与您相同: { "type": "delete", "id": "4e41b5a6f3d94aa4891ab8f9abca94e6" } 但如果它是批次的一部分,它会成功: [{ "type": "delete", "id": "4e41b5a6f3d94aa4891ab8f9abca94e6" }] 我意识到你在上面的例子中显示了一个json数组,但值得仔细检查,因为当你试图发布一个不属于数组的单个文档时,你会得到完全相 ...
  • Amazon Elasticsearch Service提供了Elasticsearch和Kibana的完全托管实施。 它通常用于日志文件的近实时可视化(但可以处理许多使用情况)。 Amazon CloudSearch基于Apache Solr。 它要求将数据作为文档加载,并且对于全文搜索有好处,并且对语言和语法(例如,同义词,要忽略的词)有所了解。 所以,真正归结为您是否想要使用Elasticsearch或Solr。 Amazon Elasticsearch Service provides a full ...
  • 目前,AWS CloudSearch内部不支持此类搜索 Currently there is no support for this kind of search inside AWS CloudSearch
  • 在cloudsearch中,无法在半径范围内搜索Latlons。 您可以按距离订购,但您可以在半径内搜索。 由于您希望半径范围内的所有结果。 而是创建一个矩形,使其四边接触要搜索的圆。现在,您可以在边界框矩形内搜索并返回按距离排序的结果。 缺点是在边界框的角落会有一些结果,所以它们不在圆圈中,但它们会出现在cloudsearch结果中。 您可以使用它们以及近似值或根据距离进一步过滤。 这是一个相同的示例查询:q = user *&fq = location%3A%5B%2740.628611,-100.69 ...
  • 如果您忽略该消息并上传文档,会发生什么? 我想您可以使用搜索字段进行搜索:review_rating_i What happens if you just ignore the message and Upload Documents? I think you may be able to search with Search Fields: review_rating_i
  • 不,它不支持'成千上万'。 问题是查询是GET请求,服务器对URL的长度有限制。 对于CloudSearch,该限制似乎是5532个字符; 超越它,你会得到HTTP状态码413 FULL HEAD的错误。 我通过向CloudSearch发出请求来确定实验,我在其中更改了查询字符串的长度; 我在任何地方都没有在他们的文档中看到它。 No, it does not support 'thousands and thousands'. The issue is that queries are GET reque ...
  • 如果您收到以下错误 403禁止通过管理规则禁止请求。 如果你确定你有适当的规则,我会检查你正在使用的API网址。 确保你使用的是正确的端点。 如果您正在进行批量上传,则api端点应如下所示 您的搜索-doc的端点/ 2013-01-01 /文件/批 注意2013-01-01,这是url的必需部分。 这是您将使用的api版本。 即使它有意义,你也不能做到以下几点 your-search-doc-endpoint / documents / batch < - 不起作用 要搜索您需要点击以下api 您的搜索端点 ...
  • 通过De Morgan的定理 ,你可以重写 (and (not sc:1) (not sc:4) (not sc:9) (not sc:13) (not sc:14)) 如 (not (or sc:1 sc:4 sc:9 sc:13 sc:14)) 我认为这并不完全是你所希望的,因为它重复了sc: term,但有点简单 By De Morgan's Theorem, you can rewrite (and (not sc:1) (not sc:4) (not sc:9) (not sc:13) (not ...
  • 尼基尔就在那里。 在您的数据为CRUD的代码中,您将类似的调用添加到cloudsearch,但这两个语句都需要包含在事务上下文中。 这基本上确保了如果一个失败,它们都会失败。 没有这个,你永远无法保证同步。 Spring和Rails等框架提供了此功能,但您尚未说明您正在使用的内容。 Nikhil is halfway there. In the code where your data is CRUD'd you add the analogous calls to cloudsearch, but bot ...
  • 我找到了回答我自己的问题。 “CloudSearchDomain”位于与“CloudSearch”分开的另一部分中。 我觉得很傻 http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudSearchDomain.html I found answer to my own question. "CloudSearchDomain" is in another section separated from "CloudSearch". i feel ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)