需要指导:后端SQL逻辑,用于前端用户动态选择字段
我的数据集如下:需要指导:后端SQL逻辑,用于前端用户动态选择字段,sql,oracle,scala,apache-spark-sql,amazon-athena,Sql,Oracle,Scala,Apache Spark Sql,Amazon Athena,我的数据集如下: 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,20
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
给定:
- 如何填充按年份和商品分组的所有国家组合的行,以便其具有所有可能组合的数据
- 鉴于我可以填充所有行的组合,报告工具将如何理解根据用户选择的国家/地区选择哪个派生行,因为该行标记为美国+阿根廷,该行标记为美国+不丹,等等
注2:尽管我在另一个问题中阐述了同样的问题,但发布此问题的唯一目的是因为我不想将我天真的方法强加给试图解决问题的人,因此,在这里,我对问题的定义比寻求解决方案的帮助更清晰。然而,在另一个问题中,我给出了实现预期结果的方法。如果你想看另一个问题,你可以这样开始:
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
这将为您提供包含所有国家/年组合的所有行以及主表中的可选数据,因此您现在可以添加过滤器/分组我不想查看年份组合,对于任何国家/地区组合,各自的金额应按商品和年份进行汇总。突出问题中的公式。@AakashBasu您的第一个问题是
如何填充按年份分组的所有国家/地区组合的行
-我向您展示了如何操作,基于此,您可以扩展/添加更多分组/公式。我想我必须运行并查看结果,然后将结果反馈给您。如果你愿意,你也可以通过这个问题底部的链接问题,深入挖掘需求。