• <bdo id='tefw5'></bdo><ul id='tefw5'></ul>
    <legend id='tefw5'><style id='tefw5'><dir id='tefw5'><q id='tefw5'></q></dir></style></legend>

        <small id='tefw5'></small><noframes id='tefw5'>

        <tfoot id='tefw5'></tfoot>
        <i id='tefw5'><tr id='tefw5'><dt id='tefw5'><q id='tefw5'><span id='tefw5'><b id='tefw5'><form id='tefw5'><ins id='tefw5'></ins><ul id='tefw5'></ul><sub id='tefw5'></sub></form><legend id='tefw5'></legend><bdo id='tefw5'><pre id='tefw5'><center id='tefw5'></center></pre></bdo></b><th id='tefw5'></th></span></q></dt></tr></i><div id='tefw5'><tfoot id='tefw5'></tfoot><dl id='tefw5'><fieldset id='tefw5'></fieldset></dl></div>

      1. 需要指导:后端 SQL 逻辑,用于前端用户动态选择

        时间:2023-08-20
          <tfoot id='T1HrB'></tfoot>

        1. <i id='T1HrB'><tr id='T1HrB'><dt id='T1HrB'><q id='T1HrB'><span id='T1HrB'><b id='T1HrB'><form id='T1HrB'><ins id='T1HrB'></ins><ul id='T1HrB'></ul><sub id='T1HrB'></sub></form><legend id='T1HrB'></legend><bdo id='T1HrB'><pre id='T1HrB'><center id='T1HrB'></center></pre></bdo></b><th id='T1HrB'></th></span></q></dt></tr></i><div id='T1HrB'><tfoot id='T1HrB'></tfoot><dl id='T1HrB'><fieldset id='T1HrB'></fieldset></dl></div>
            <tbody id='T1HrB'></tbody>
          • <bdo id='T1HrB'></bdo><ul id='T1HrB'></ul>
            <legend id='T1HrB'><style id='T1HrB'><dir id='T1HrB'><q id='T1HrB'></q></dir></style></legend>

              <small id='T1HrB'></small><noframes id='T1HrB'>

                • 本文介绍了需要指导:后端 SQL 逻辑,用于前端用户动态选择字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个数据集如下:

                  Country,Commodity,Year,Type,Amount
                  US,Vegetable,2010,Harvested,2.44
                  US,Vegetable,2010,Yield,15.8
                  US,Vegetable,2010,Production,6.48
                  US,Vegetable,2011,Harvested,6
                  US,Vegetable,2011,Yield,18
                  US,Vegetable,2011,Production,3
                  Argentina,Vegetable,2010,Harvested,15.2
                  Argentina,Vegetable,2010,Yield,40.5
                  Argentina,Vegetable,2010,Production,2.66
                  Argentina,Vegetable,2011,Harvested,15.2
                  Argentina,Vegetable,2011,Yield,40.5
                  Argentina,Vegetable,2011,Production,2.66
                  Bhutan,Vegetable,2010,Harvested,7
                  Bhutan,Vegetable,2010,Yield,35
                  Bhutan,Vegetable,2010,Production,5
                  Bhutan,Vegetable,2011,Harvested,2
                  Bhutan,Vegetable,2011,Yield,6
                  Bhutan,Vegetable,2011,Production,3
                  

                  鉴于:

                  1. 如果任何一个国家在数据中有 n 年,所有其他国家也应有相同的 n 年.例如:如果美国有 2011 年和 2012 年的数据,那么所有其他国家/地区都将有 2011 年和 2012 年的数据.

                  条件:

                  1. 聚合仅在多国选择时发生.将按商品和年份分组.

                  例如:如果前端工具中的用户选择美国和阿根廷,我们必须显示 -

                  Eg: If a user in the frontend tool selects US and Argentina, we have to show -

                  衍生产量的数量 =(美国收获量 + 阿根廷收获量)/(美国产量 + 阿根廷产量),即 (2.44+15.2)/(6.48+2.66),同样,对于三个国家,它将是三个收获值的相加除以三个产值的相加,依此类推.必须将其填充到新行中.

                  The Amount for Derived Yield = (Harvested of US + Harvested of Argentina)/(Production of US + Production of Argentina), i.e., (2.44+15.2)/(6.48+2.66), similarly for three countries it will be addition of three harvested value divided by addition of three production value and so on. That has to be populated in a new row.

                  注意:前端用户可以选择任意国家/地区组合.在后端执行而不是在前端动态执行的唯一目的是因为 AWS QuickSight(我们的可视化工具)虽然可以在选定的列过滤器上填充总和,但尚不支持对那些衍生的求和字段进行计算.因此,必须预先填充所有国家/地区组合的整个计算(非常幼稚的方法),以便在报告中提供.

                  Note: The users in the frontend can select any combination of countries. The sole purpose of doing it in the backend rather than dynamically doing it in the frontend is because AWS QuickSight (our visualisation tool), even though can populate sum on selected column filters but doesn't yet support calculation on those derived summed fields. Hence, the entire calculation of all combination of countries has to be pre-populated (very naive approach) in order to make it available in report.

                  我向所有 SQL 专家提出的两个问题是:

                  Two of my question to all SQL experts is:

                  • 如何填充按年份和商品分组的所有国家/地区组合的行,以便包含所有可能组合的数据.
                  • 鉴于我可以填充所有行组合,报告工具将如何根据用户选择的国家/地区了解选择哪个派生行,因为该行标记为美国 + 阿根廷,该行为美国 + 不丹,等

                  非常欢迎任何解决方案.

                  Any solution is extremely welcome.

                  首选 SQL 工具:Spark SQL 或 Athena SQL(在 Presto 上运行)或 HiveQL.次选:Oracle、PGSQL

                  SQL Tool preferred: Spark SQL or Athena SQL (runs on Presto) or HiveQL. Less preferred: Oracle, PGSQL

                  注意 2:发布这个问题的唯一目的,即使我已经在另一个问题中详细阐述过,也是因为我不想将我的天真方法强加给试图解决问题的人问题,所以在这里,与寻求解决方案的帮助相比,我更清楚地定义了问题.而在另一个问题中,我已经给出了预期结果的方法.如果您想查看其他问题,这里是.

                  Note 2: The sole purpose of posting this question, even though I've elaborated the same in another one is because I don't want to impose my naive approach on somebody trying to solve the problem, so here, I've defined the problem with more clarity than asking for help in solution. Whereas, in the other question I have given my approach for the expected result. In case if you want to see the other question, here it is.

                  推荐答案

                  你可以从这样的事情开始:

                  you can start with something like this:

                  select * from
                  (
                      select c.Country, y.Year
                      from
                      (select distinct Country from table) as c,
                      (select distinct Year from table) as y
                  ) as cy
                  left join table as t on t.Country = cy.Country and t.Year = cy.Year
                  

                  这将为您提供包含国家/年所有组合的所有行以及主表中的可选数据,因此您现在可以添加过滤器/分组

                  this will give you all rows with all combinations of Country/Year and optionally data from main table, so you can now add filter/grouping

                  这篇关于需要指导:后端 SQL 逻辑,用于前端用户动态选择字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:SQLITE_ERROR:通过 JDBC 从 Spark 连接到 SQLite 数据库时 下一篇:将数据从 oracle 移动到 HDFS,处理并从 HDFS 移动到

                  相关文章

                  最新文章

                    • <bdo id='jQAxy'></bdo><ul id='jQAxy'></ul>
                  1. <tfoot id='jQAxy'></tfoot>

                  2. <legend id='jQAxy'><style id='jQAxy'><dir id='jQAxy'><q id='jQAxy'></q></dir></style></legend>

                    <small id='jQAxy'></small><noframes id='jQAxy'>

                    1. <i id='jQAxy'><tr id='jQAxy'><dt id='jQAxy'><q id='jQAxy'><span id='jQAxy'><b id='jQAxy'><form id='jQAxy'><ins id='jQAxy'></ins><ul id='jQAxy'></ul><sub id='jQAxy'></sub></form><legend id='jQAxy'></legend><bdo id='jQAxy'><pre id='jQAxy'><center id='jQAxy'></center></pre></bdo></b><th id='jQAxy'></th></span></q></dt></tr></i><div id='jQAxy'><tfoot id='jQAxy'></tfoot><dl id='jQAxy'><fieldset id='jQAxy'></fieldset></dl></div>